工具栏标题的项目对齐问题?
今天我已经陷入了一个奇怪的问题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
右侧。请帮我把短路从这个问题。
@MikeM。建议已为我工作。有关问题的更多细节,请参考以下链接click here
我所做的一切得到从问题驱除掉是我已删除了Toolbar
内LinearLayout
和设定的android:layout_gravity
帮助视图的严重性,请请参考下面的解决方案
<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">
<TextView
android:id="@+id/headerTxt"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="marquee"
android:maxLines="1"
android:text="Tile"
android:textColor="@android:color/black" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:src="@drawable/chat_new_icon" />
</android.support.v7.widget.Toolbar>
只需更新代码...编辑您的相对布局实现
<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: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_toRightOf="@+id/headerTxt"
android:layout_centerVertical="true"
/>
</RelativeLayout>
没有工作@MohdSaquib :( –
你会给你的风格/ AppTheme.NoActionBar.PopupOverlay –
请检查'' –
这是工作......
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:local="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#3EC3D6"
app:layout_collapseMode="pin"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<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:layout_centerInParent="true"
android:ellipsize="marquee"
android:maxLines="1"
android:text="Tile"
android:textColor="@android:color/black" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/headerTxt"
android:src="@drawable/delete_icon" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
我已经尝试过urs第二个解决方案,但它也不工作,请检查从上面的代码输出。 ibb.co/m7Zqzv –
我再次提到代码和屏幕截图输出是什么,我发布它 –
这是什么来在我结束
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:local="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#3EC3D6"
app:layout_collapseMode="pin"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<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:layout_centerInParent="true"
android:ellipsize="marquee"
android:maxLines="1"
android:text="Tile"
android:textColor="@android:color/black" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/headerTxt"
android:src="@drawable/delete_icon" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
我需要@MohdSaquib,标题应该在中心和图像在右边.. –
在我的解决方案,我认为你的要求是满足的,它不会完美地归因于动作栏属性和其他细节克是显示在图像我share.4 –
我需要它中心bro..That什么我问了SO.Thanks的问题,谢谢你的价值罢了时间 –
尝试添加应用程序:contentInsetEnd = “0dp” 应用:contentInsetEndWithActions = “0dp” 应用:contentInsetLeft = “0dp” 应用:contentInsetRight = “0dp” 应用:contentInsetStart = “0dp” 应用程序: contentInsetStartWithNavigation =“0dp”在工具栏 –
@DivyeshPatel已尝试urs建议不工作:( –
也尝试设置内部布局高度以匹配父母 –