Friday, 25 March 2016

XML : Android - Scale TableLayout to Screen Size

I have an Android app that contains a RelativeLayout with a TableLayout inside of it.

Within the TableLayout there are 3 ImageViews for each of the 3 TableLayout rows. (Making 9 in total)

The problem I'm having is that the last ImageView in each row is partially cut off.

This is my current xml code:

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_gravity="center"      tools:context=".Main">      <TableLayout              android:layout_width="fill_parent"              android:layout_height="wrap_content"              android:layout_alignParentRight="true"              android:shrinkColumns="true"              android:id="@+id/TableLayout">              <TableRow                  android:id="@+id/TableRow1"                  android:layout_width="fill_parent"                  android:layout_height="wrap_content">                  <ImageView                       android:id="@+id/s1"                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:padding="5dp"/>                  <ImageView                       android:id="@+id/s2"                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:padding="5dp"/>                  <ImageView                       android:id="@+id/s3"                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:padding="5dp"/>              </TableRow>      </TableLayout>  </RelativeLayout>    

(The rest of the rows are the same)

I have tried playing around with values like fill_parent and wrap_content but I haven't had any success yet.

I would like to scale the TableLayout to the size of the screen, so that it looks good on all devices, without any of the images getting cut off.

Thanks in advance!

No comments:

Post a Comment