隐藏ImageButton背景时,如何防止图标对齐更改?

时间:2012-11-14 00:42:38

标签: android xamarin.android android-actionbar imagebutton android-spinner

我的应用程序操作栏中有一个ImageButton,我用它来模拟一个微调器,通过选择标题来改变视图(我使用MonoDroid.ActionBar作为起点 - http://bit.ly/UBzI77)。

ImageButton-Before

这是ImageButton的XML。

 <ImageButton
      android:id="@+id/title_spinner_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_toRightOf="@+id/actionbar_title"/>

当我通过向XML添加android:background属性来使ImageButton背景透明时。

 <ImageButton
      android:id="@+id/title_spinner_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_toRightOf="@+id/actionbar_title" 
      android:background="@null"/>

ImageButton背景消失,但图标垂直居中。

ImageButton-After

是否有人知道如何使ImageButton背景透明,但图标对齐在ImageButton的底部?

提前致谢。

1 个答案:

答案 0 :(得分:2)

结合空背景尝试以下内容:

android:layout_alignParentBottom="true"
android:layout_marginBottom="3dp" // this is here just to ensure the image doesn't sit flush against the bottom of the bar, vary as required

或者,您可以尝试

android:layout_height="match_parent"
android:gravity="bottom"