Android center custom view in actionbar

前端 未结 2 1315
遥遥无期
遥遥无期 2021-01-05 06:44

Trying to set a custom view for my actionbar, but have the problem that it doesn\'t fill up the entire width of the actionbar which makes it har for me to center objects. Ho

相关标签:
2条回答
  • 2021-01-05 07:37

    You have to set android:layout_width="wrap_content" for your RelativeLayout in your actionbar_layout.xml; this, in conjunction with android:layout_gravity="center", allows to center your custom view in the ActionBar.

    0 讨论(0)
  • 2021-01-05 07:41

    As far as I am concerned, the thing is that the upper layout is always streched to the inner view height and weight. You can make it work just by setting layout_height="match_parent" in the TextView:

    <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:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/actionbar_title"
            />
    </LinearLayout>
    
    0 讨论(0)
提交回复
热议问题