为什么我在我的自定义动作条形象有不需要的左填充 [英] Why my image on my custom Actionbar has unwanted left padding
问题描述
我定制了动作条
通过膨胀的自定义视图。
和我的自定义操作栏的XML布局是:
I customized the ActionBar
by inflating a custom view.
and my custom action bar XML layout is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:background="@drawable/actionbar_bg" >
<TextView
android:id="@+id/ab_main_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:gravity="right|center_vertical"
android:text="heaer_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/ab_main_img0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
android:src="@drawable/ab_main_img_layer_list" />
</RelativeLayout>
但我不知道为什么会出现不必要的左填充我的的ImageView
在运行时!像下图:
but I don't know why there is an unwanted left padding for my ImageView
at run time!!! like image below:
有人知道?
推荐答案
看来,当你在你的自定义操作栏的XML布局中使用WRAP_CONTENT或match_parent在你的ImageView的(不是TextView的),你将有填充在你的行动吧,否则你没有。
It seems that when you use "wrap_content" or "match_parent" in your ImageView (not TextView) on your custom action bar xml layout, you will have padding in your action bar, otherwise you don't have.
所以,请尝试更改如下您的xml:固定的大小设置为ImageView的(你还可以添加一些margin_left美好的样子)
So please try changing your xml as below: setting fixed size to the ImageView (and you can also add some margin_left for a better look).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:background="@drawable/actionbar_bg" >
<TextView
android:id="@+id/ab_main_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:gravity="right|center_vertical"
android:text="heaer_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/ab_main_img0"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:clickable="true"
android:src="@drawable/ab_main_img_layer_list" />
</RelativeLayout>
编辑:只是编辑我的答案的问题:)更准确的解释。希望这将有助于其他人。
Just edited my answer for a more accurate explanation of the issue :). Hope it will help others as well.
这篇关于为什么我在我的自定义动作条形象有不需要的左填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!