2017-04-19 18 views
0

センターでタイトルバーを達成するにはどうすればよいですか?私は下の写真で描いた青い線の上に正確にしたい。事前ここセンター上のタイトルバー

のおかげで、私のコードです:

touchでは:

 getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
     getSupportActionBar().setCustomView(R.layout.abs_layout); 

XML:

 <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:text="Home" 
    android:textColor="#ffffff" 
    android:id="@+id/mytext" 
    android:textSize="18sp" /> 

    </LinearLayout> 

マイ出力: 私はそのまさに私が描いた青いラインにしたいです下の図のように。

I want its exactly on the blue line that I drew on the picture below.

+0

[Androidのツールバーセンターのタイトルとカスタムフォント](http://stackoverflow.com/a/26548766/7871886) –

+0

まだ同じこと: )まだ正確に中心にない – CS9423

+0

私はあなたのソリューションは既に[ここ](http://stackoverflow.com/questions/432037/how-do-i-center-text-horizo​​ntally-and-vertically-in-a-textview -on-android?page = 1&tab = votes#tab-top) –

答えて

0

利用RelativeLayoutの代わりLinearLayoutandroid:layout_gravityLinearLayoutで動作しません。

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_horizontal"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:text="Home" 
     android:textColor="#ffffff" 
     android:id="@+id/mytext" 
     android:textSize="18sp" /> 

</RelativeLayout> 
+0

既に試してみました。まだ中心にない – CS9423

0

カスタムツールバーを作成するだけです。 TextViewの活動の

<android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/mypay_purple"> 

      <TextView 
       android:id="@+id/title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       style="@style/FontNormal" 
       android:textColor="@color/mypay_white" 
       android:text="Title" 
       /> 

     </android.support.v7.widget.Toolbar> 
</android.support.design.widget.AppBarLayout> 

に重力を追加

setSupportActionBar(toolbar); 
if (getSupportActionBar() != null) { 
    getSupportActionBar().setDisplayShowTitleEnabled(false); 
    title.setText("Payment"); 
} 
関連する問題