2016-05-30 10 views
1

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> 
+0

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? –

+0

Ich denke schon, aber ich bin mir nicht sicher –

+0

Haben Sie Ihre Schwerkraft in Ihrem Stil hier überschrieben: app: titleTextAppearance = "@ style/toolbarTitleText"? – BHuelse

Antwort

0

fügen Sie eine Textview in Ihrer Symbolleiste

wie folgt aus:

<android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/> 

    </android.support.v7.widget.Toolbar> 
+0

hinzugefügt Dies war nicht das, was ich gesucht habe, auch habe ich das schon einmal versucht, siehe: http://StackOverflow.com/Questions/37479043/android-multiline-toolbar-title –

+0

so Bitte Bild hinzufügen lassen Sie mich wissen, was Sie wollen –

0

Versuchen Sie Folgendes zu tun:

1- den Titel Deaktivieren von getSupportActionBar().setDisplayShowTitleEnabled(false);

2- hinzufügen Textview unter Ihrem toolbar als Symbolleiste Titel mit:

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/toolbar_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top"/> 

</android.support.v7.widget.Toolbar> 
+0

Ich habe das schon einmal versucht, aber es hat nicht wirklich funktioniert, siehe: http://stackoverflow.com/questions/37479043/android-multiline-toolbar-title –