Mikael
Mikael

Reputation: 805

Android add TableLayout and LinearLayout together?

I have a basic LinearLayout with a TableLayout and ImageView inside, i want to have the table at top then the picture at botton center, how can i fix this? Thur the java code i add all the rows into TableLayout so want be seen here in the code.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:showAsAction="ifRoom">

<TableLayout
    android:id="@+id/Table"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1"
    android:shrinkColumns="0">
</TableLayout>

<!--<LinearLayout-->
    <!--android:layout_gravity="bottom"-->
    <!--android:id="@+id/secLayout"-->
    <!--android:orientation="vertical"-->
    <!--android:layout_width="wrap_content"-->
    <!--android:layout_height="wrap_content">-->

    <ImageView
        android:id="@+id/pic1"
        android:src="@mipmap/pic1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>

<!--</LinearLayout>-->

Any ideas?

Upvotes: 2

Views: 926

Answers (2)

Linh
Linh

Reputation: 60973

Please check my solution

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    app:showAsAction="ifRoom"  // remove it
    >
    <TableLayout
        android:id="@+id/Table"
        android:layout_width="match_parent"
        android:layout_height="0dp" // change it
        android:layout_weight = 1 // add it
        android:stretchColumns="1"
        android:shrinkColumns="0">
    </TableLayout>

    <ImageView
        android:id="@+id/pic1"
        android:src="@mipmap/pic1"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>

</LinearLayout>

Hope this help

Upvotes: 2

Rajesh Jadav
Rajesh Jadav

Reputation: 12861

Try using RelativeLayout instead of LinearLayout as Parent layout.

Use android:layout_alignParentBottom="true" to align ImageView at bottom and android:layout_centerHorizontal="true" to align ImageView in center.

Try this code.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:showAsAction="ifRoom">

    <TableLayout
        android:id="@+id/Table"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/pic1"
        android:stretchColumns="1"
        android:shrinkColumns="0">
    </TableLayout>

    <ImageView
        android:id="@+id/pic1"
        android:src="@mipmap/pic1"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>

</RelativeLayout>

Upvotes: 0

Related Questions