android在tablerow中设置imagebutton

android在tablerow中设置imagebutton,android,center,imagebutton,Android,Center,Imagebutton,我在TableLayout/TableRow中有一个ImageButton 我想将ImageButton展开到整个TableRow上并设置图片 在按钮的中心(高度类似于tablerow/按钮高度) 我在布局文件中设置了 <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableRow > <ImageButto

我在TableLayout/TableRow中有一个ImageButton

我想将ImageButton展开到整个TableRow上并设置图片 在按钮的中心(高度类似于tablerow/按钮高度)

我在布局文件中设置了

 <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 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>

您可以将此代码用于高度和宽度

<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>

试试这个:

<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>

是的,宽度正在工作:)谢谢,但是。。。不是身高。。。layout\u height=填充父对象不工作我有这个问题,您找到解决方案了吗?
<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>
<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>