2015-10-25 37 views
0

我在嘗試在我的佈局中使用圖像按鈕時出現問題。當我添加第一個圖像按鈕時,一切正常,但是當我添加第二個時,第一個縮小,這取決於我使用的佈局嗎?我設置了相對佈局,但我不知道如何保持每個按鈕的大小相同。如何爲android應用程序設置自定義圖像按鈕?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="com.example.supernovastudios.conguate.preguntas3" 
android:background="#222222"> 


<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageButton5" 
    android:background="@drawable/botonpregunta" 
    android:layout_centerHorizontal="true" /> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/botonpregunta" 
    android:id="@+id/imageButton6" 
    android:layout_alignTop="@+id/imageButton5" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="143dp" /> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:background="@drawable/botonpregunta" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageButton7" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginBottom="104dp" /> 

enter image description here

這是佈局的圖片。中間的按鈕是唯一能夠保持其原始尺寸的按鈕,而其他按鈕在我向上或向下移動時似乎會縮小。

+0

你能後的XML代碼? – Sameer

+0

如果您需要幫助修復,請使用您的代碼編輯問題! – OBX

+0

@Sameer我上傳了代碼!對不起,我花了這麼長時間 – user3390742

回答

0

你使用的圖像爲background在您的ImageButtons

你應該ImageButton

例子中使用的圖像作爲src

<ImageButton 
    android:id="@+id/imageButton5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleType="fitCenter" 
    android:adjustViewBounds="true" 
    android:src="@drawable/botonpregunta" /> 
+0

我用它作爲一個src,它失去了它的圓形,當它縮小時它會恢復嗎? – user3390742

+0

顯示您的圖像。角落可能被切碎成更大的圖像。也檢查[this](http://stackoverflow.com/a/15117536/1529129)。檢查更新的答案以及 –

+0

爲什麼不添加樣式來獲得圓角? – Sameer

相關問題