0

我在我的應用程序的Action Bar中有一個ImageButton,用於通過選擇標題(我使用MonoDroid.ActionBar作爲起點 - http://bit.ly/UBzI77)來模擬更改視圖的微調控制器。隱藏ImageButton背景時,如何防止圖標對齊更改?

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的底部排列圖標?

在此先感謝。

+0

你用'機器人出場:scaleType'?例如:'android:scaleType =「matrix」'。選項是MATRIX,FIT_START,FIT_END等。[來源](http://developer.android.com/reference/android/widget/ImageView.ScaleType.html) – jnthnjns

回答

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" 
+0

Xono - 你的android:layout_height/android:引力建議工作。謝謝! – billmaya

+0

Xono - android:layout_alignParentBottom/android:layout_marginBottom組合將圖標放在ImageButton的底部,但不管您將marginBottom設置爲圖標的位置是否從其初始位置移開。 – billmaya

+0

真的嗎?它應該有效 - 事實上,我有點期待第一個工作,第二個打破,而不是相反。看起來RelativeLayout的alignParent和邊距在一起玩起來不太好。可以嘗試用'android:paddingBottom =「3dp」'替換marginBottom,看看它是否更好。 – Xono