问题描述
今天,我陷入了Toolbar
自定义标头的怪异问题之一.
我正在使用中心的TextView
和Toolbar
右侧的ImageView
.因此,我在xml中使用了以下代码行,请检查一下.
Today i have stucked in one of the weird problem in Toolbar
custom header.
I am using the TextView
in the center and ImageView
which is at the right of the Toolbar
. So i have used below lines of code in xml , please check it once.
<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>
并从上面的代码中获取这些输出.
And getting these output from above code.
我已经使用RelativeLayout
来解决此问题,但是它也没有用.请检查以下代码
I have used the RelativeLayout
for it to come out from this problem, But it also NOT worked.Please check the below code for it
<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>
如果还有其他意外结果,请检查一次.
And getting another unexpected result please check it once.
我已经参考了此解决方案,但不适用于我.请检查链接一次.
1.第一链接
2.第二个链接
3.第三链接
4.第四次链接
I have already refer this solution but it is not working for me.Please check the link once.
1. First Link
2. Second Link
3. Third Link
4. Forth Link
我需要TextView
应该位于Toolbar
的中心,而ImageView
应该位于Toolbar
的右边.请帮助我简化此问题.
What i need that TextView
should at the center of the Toolbar
and ImageView
should at the right of the Toolbar
.Please help me to short out from this problem.
推荐答案
@MikeM..建议对我有用.有关此问题的更多详细信息,请参考此链接单击此处
@MikeM. suggestion has worked for me. For more detail on the issue please refer this link click here
我为摆脱该问题所做的事情是,我已经删除了Toolbar
内的LinearLayout
并借助android:layout_gravity
设置了视图的重力,请参考以下解决方案
What i have done to get rid off from the problem is that I have removed the LinearLayout
inside the Toolbar
and set the gravity of the view with help of android:layout_gravity
, Please refer the below solution for it
<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>
并从上述代码中获得预期结果,请检查一次.
And getting the expected result from above code, please check it once.
这篇关于工具栏标题的项目对齐问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!