Java 我的TableLayout中的项目在Eclipse中没有对齐

Java 我的TableLayout中的项目在Eclipse中没有对齐,java,android,eclipse,layout,Java,Android,Eclipse,Layout,我试图让我的Android布局在顶部有两个ImageView,每个水平方向占据一半空间,在两个ImageView下面总共有3个按钮,如下图所示 [imageview][imageview] [butn1][butn2][butn3] 但是,两个图像视图都被约束到butn1的右侧,如下所示 [i1][i2] [butn1][butn2][butn3] 我的代码如下 <TableLayout xmlns:android="http://schemas.android.com/apk/res/

我试图让我的Android布局在顶部有两个ImageView,每个水平方向占据一半空间,在两个ImageView下面总共有3个按钮,如下图所示

[imageview][imageview]
[butn1][butn2][butn3]

但是,两个图像视图都被约束到butn1的右侧,如下所示

[i1][i2]
[butn1][butn2][butn3]

我的代码如下

<TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/background_dark"
android:orientation="horizontal"
android:stretchColumns="*" >

<TableRow 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="9" >

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5"  >

            <ImageView
                android:id="@+id/boobs_image_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5" >

            <ImageView
                android:id="@+id/kittens_image_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:adjustViewBounds="true" />
        </RelativeLayout>
    </LinearLayout>
</TableRow>

<TableRow 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <Button 
        android:id="@+id/save_boobs_internal_storage_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Save titties"
        style="@style/ButtonTheme" />

    <Button 
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Next"
        style="@style/ButtonTheme" />

    <Button 
        android:id="@+id/save_kitty_internal_storage_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Save kitty"
        style="@style/ButtonTheme" />

</TableRow>

</TableLayout>

尝试此修改后的布局:

 <TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/background_dark"
    android:orientation="horizontal"
    android:stretchColumns="*" >

    <TableRow 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="1">


                <ImageView
                android:id="@+id/boobs_image_view"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5"/>


                <ImageView
                android:id="@+id/kittens_image_view"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5" />

    </TableRow>

    <TableRow 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="9" >

        <Button 
            android:id="@+id/save_boobs_internal_storage_button"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:text = "Save titties"
            style="@style/ButtonTheme" />

        <Button 
            android:id="@+id/next_button"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:text = "Next"
            style="@style/ButtonTheme" />

        <Button 
            android:id="@+id/save_kitty_internal_storage_button"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:text = "Save kitty"
            style="@style/ButtonTheme" />

    </TableRow>

    </TableLayout>

尝试此修改后的布局:

 <TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/background_dark"
    android:orientation="horizontal"
    android:stretchColumns="*" >

    <TableRow 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="1">


                <ImageView
                android:id="@+id/boobs_image_view"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5"/>


                <ImageView
                android:id="@+id/kittens_image_view"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5" />

    </TableRow>

    <TableRow 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="9" >

        <Button 
            android:id="@+id/save_boobs_internal_storage_button"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:text = "Save titties"
            style="@style/ButtonTheme" />

        <Button 
            android:id="@+id/next_button"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:text = "Next"
            style="@style/ButtonTheme" />

        <Button 
            android:id="@+id/save_kitty_internal_storage_button"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:text = "Save kitty"
            style="@style/ButtonTheme" />

    </TableRow>

    </TableLayout>

我想出来了

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/background_dark" >

<LinearLayout 
    android:id="@+id/imagesLinearLayout"
    android:orientation="horizontal"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"  >

        <ImageView
            android:id="@+id/boobs_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5" >

        <ImageView
            android:id="@+id/kittens_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:adjustViewBounds="true" />
    </RelativeLayout>
</LinearLayout>

<LinearLayout 
    android:id="@+id/buttonLinearLayout"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <Button 
        android:id="@+id/save_boobs_internal_storage_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text = "Save titties"
        style="@style/ButtonTheme" />

    <Button 
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text = "Next"
        style="@style/ButtonTheme" />

    <Button 
        android:id="@+id/save_kitty_internal_storage_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text = "Save kitty"
        style="@style/ButtonTheme" />
</LinearLayout>

</RelativeLayout>

我想出来了

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/background_dark" >

<LinearLayout 
    android:id="@+id/imagesLinearLayout"
    android:orientation="horizontal"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"  >

        <ImageView
            android:id="@+id/boobs_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5" >

        <ImageView
            android:id="@+id/kittens_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:adjustViewBounds="true" />
    </RelativeLayout>
</LinearLayout>

<LinearLayout 
    android:id="@+id/buttonLinearLayout"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <Button 
        android:id="@+id/save_boobs_internal_storage_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text = "Save titties"
        style="@style/ButtonTheme" />

    <Button 
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text = "Next"
        style="@style/ButtonTheme" />

    <Button 
        android:id="@+id/save_kitty_internal_storage_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text = "Save kitty"
        style="@style/ButtonTheme" />
</LinearLayout>

</RelativeLayout>


我用它替换了两个表行中的代码,但现在图像不再调整大小以占据屏幕的其余部分。我用它替换了两个表行中的代码,但现在图像不再调整大小以占据屏幕的其余部分。不要使用表来对齐元素,有更好的方法来对齐图元。表格用于以格式化布局显示数据。可以使用LinearLayout或RelativeLayout,但绝对不能使用TableLayout。不要使用表格来对齐元素,有更好的方法来对齐元素。表格用于以格式化布局显示数据。要么使用LinearLayout,要么使用RelativeLayout,但绝对不要使用TableLayout。