2013-08-17 44 views
1

我在TableLayout/TableRow中有一個ImageButton。android set imagebutton in tablerow

我想在整個的TableRow傳播的ImageButton和設置PIC 在按鈕(高度像tablerow的/按鈕高度)

我在layoutfile設置的中心......

<TableLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 


    <TableRow > 

    <ImageButton 
     android:id="@+id/CarPic" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     android:onClick="onButtonClick" 
     android:scaleType="centerInside" 
     android:src="@drawable/etype" /> 

</TableLayout> 

當應用程序啓動默認PIC看起來像我描述 - 但是當我oncli更改CK按鈕的PIC ... 按鈕大小調整爲PIC高度/在右上角寬度的住宿

代碼填充該

Drawable d = Drawable.createFromPath(Path); 
    LPic.setImageDrawable(d); 

我已經嘗試了許多不同的版本:(和包裹,但 該鍵可以改變每一個畫面

+0

我有這個問題,你有沒有發現任何解決方案? –

回答

0

使用此code.You必須定義重屬性用於此

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 
<TableRow> 
    <ImageButton 
     android:id="@+id/CarPic" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:onClick="onButtonClick" 
     android:src="@drawable/ic_launcher" 
     android:layout_weight="1.0" /> 
</TableRow> 
</TableLayout> 
+0

是的,寬度現在工作:)謝謝,但是...不是高度... layout_height =填寫父母不起作用 –

0

你可以使用此代碼高度和寬度

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<TableRow 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1.0" > 

    <ImageButton 
     android:id="@+id/CarPic" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1.0" 
     android:onClick="onButtonClick" 
     android:src="@drawable/ic_launcher" /> 
</TableRow> 

0

試試這個:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 
<TableRow> 
<ImageButton 
    android:id="@+id/CarPic" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_gravity="center_horizontal" 
    android:onClick="onButtonClick" 
    android:src="@drawable/ic_launcher" 
    android:layout_weight="1" /> 
</TableRow> 
</TableLayout>