Ich habe versucht, den Titel meiner Symbolleiste am oberen Rand der Symbolleiste zu starten, aber während ich den android:gravity="top"
gesetzt haben, beginnt der Text immer noch in der Mitte (vertikal) der Symbolleiste. Ich denke, das könnte etwas mit der Verwendung eines benutzerdefinierten Layouts für die Symbolleiste zu tun haben, aber ich benutze es, weil ich es brauche. Ich hoffe also, jemand weiß, wie man den Text so einstellen kann, dass er ganz oben beginnt.Text wird nicht oben beginnen mit Schwerkraft = oben
Hier ist das Layout meiner Symbolleiste ist in:
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidDomInspection -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.percent.PercentRelativeLayout
android:id="@+id/layoutProjectOverview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:title="@string/menuLabel1a"
app:layout_widthPercent="37%"
app:layout_heightPercent="26%"
android:gravity="top"
app:titleTextAppearance="@style/toolbarTitleText"
android:background="@drawable/toolbar_basic"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.percent.PercentRelativeLayout
android:id="@+id/layoutObjectNav"
app:layout_widthPercent="63%"
app:layout_aspectRatio="400%"
android:layout_toRightOf="@id/toolbar2"
android:layout_toEndOf="@id/toolbar2"
android:background="@drawable/border_basic">
<!-- Some irrelevant xml code -->
</android.support.percent.PercentRelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/layoutObjectNav">
<!-- Some more irrelevant xml code -->
</RelativeLayout>
</android.support.percent.PercentRelativeLayout>
<!-- Some more irrelevant xml code -->
</RelativeLayout>
Hier wird der Layout-Code benutzerdefinierte Symbolleiste ist:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/action_bar_title"
android:textSize="20sp"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:gravity="top"
android:padding="5dp"
android:ellipsize="end"
android:maxLines="3"/>
</LinearLayout>
Und hier ist der Code, wo ich das benutzerdefinierte Layout gesetzt (und einige andere Sachen):
@Override
protected void onResume() {
super.onResume();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar2);
setSupportActionBar(toolbar);
currentProject = getIntent().getParcelableExtra("Project");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.layout_toolbar);
((TextView) findViewById(R.id.action_bar_title)).setText(currentProject.getTitle());
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = (int)(size.x * 0.37);
int height = Math.round(size.x * 0.63f * 0.25f);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width,height);
toolbar.setLayoutParams(params);
} else {
getSupportActionBar().setTitle(currentProject.getTitle());
}
// Some irrelevant java code
}
Weiß jemand, was ich falsch mache?
EDIT:
Hier ist die TextAppearance Style I für die Symbolleiste verwenden:
<style name="toolbarTitleText">
<item name="android:textSize">20sp</item>
<item name="android:maxLines">3</item>
</style>
Mit der Größe der Symbolleiste, die Textgröße der Textview und der Polsterung Gibt es in der Symbolleiste noch Platz für die Textansicht, um sich neu zu positionieren? –
Ich denke schon, aber ich bin mir nicht sicher –
Haben Sie Ihre Schwerkraft in Ihrem Stil hier überschrieben: app: titleTextAppearance = "@ style/toolbarTitleText"? – BHuelse