今天我已经陷入了一个奇怪的问题Toolbar
自定义标题。
我在中心使用TextView
,在Toolbar
的右侧使用ImageView
。所以我在xml中使用了下面的代码行,请检查一次。工具栏标题的项目对齐问题?
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#3EC3D6"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/headerTxt"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center"
android:layout_gravity="center"
android:maxLines="1"
android:text="Tile"
android:textColor="@android:color/black" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/chat_new_icon"
android:layout_gravity="right"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
我已经使用了RelativeLayout
它从这个问题出来,但它也不是worked.Please检查下面的代码为它
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#3EC3D6"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/headerTxt"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:maxLines="1"
android:text="Tile"
android:textColor="@android:color/black" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/chat_new_icon"
android:layout_alignParentRight="true"
android:layout_gravity="right"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
我已经提到这个解决方案,但它不适合我,请检查链接一次。
1. First Link
2. Second Link
3. Third Link
4. Forth Link
我需要什么是TextView
应在Toolbar
和ImageView
中心应在Toolbar
右侧。请帮我把短路从这个问题。
尝试添加应用程序:contentInsetEnd = “0dp” 应用:contentInsetEndWithActions = “0dp” 应用:contentInsetLeft = “0dp” 应用:contentInsetRight = “0dp” 应用:contentInsetStart = “0dp” 应用程序: contentInsetStartWithNavigation =“0dp”在工具栏 –
@DivyeshPatel已尝试urs建议不工作:( –
也尝试设置内部布局高度以匹配父母 –