I am trying to create a 7 equal width columns using the include blocks. The following code seems to be working for higher resolutions, but on lower resolutions (e.g. 480x800) the last column is off the screen.
I am new to Android and I would really appreciate any advice oh how to organize the layout of reusable elements. My final goal is a board of 7x7 "cells" that can contain superposed images (that is why I used RelativeLayout
in my include).
main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.banzaitokyo.monstrarium.MainActivity">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow android:background="@color/colorPrimary">
<include layout="@layout/cell" />
<include layout="@layout/cell" />
<include layout="@layout/cell" />
<include layout="@layout/cell" />
<include layout="@layout/cell" />
<include layout="@layout/cell" />
<include layout="@layout/cell" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</LinearLayout>
cell.xml:
<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="match_parent"
android:background="@color/colorGround"
tools:showIn="@layout/activity_main">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="1dp"
android:adjustViewBounds="true"
android:background="@color/colorDesert"
android:contentDescription="@string/evil_state"
android:cropToPadding="false"
android:src="@drawable/evil" />
</RelativeLayout>