clever_trevor
clever_trevor

Reputation: 1674

The items in my TableLayout are not lining up in Eclipse

I am trying to have my Android layout have two ImageViews at the top, each taking up half the space horizontally, and 3 buttons total underneath the two imageviews, pictured below.

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

However, both imageviews are being constrained to butn1's right side, like so

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

My code is below.

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

Upvotes: 1

Views: 171

Answers (2)

clever_trevor
clever_trevor

Reputation: 1674

I figured it out

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

Upvotes: 1

tony m
tony m

Reputation: 4779

Try this modified layout:

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

Upvotes: 0

Related Questions