I am currently working on an Android application to be run on Android 6. I am completely new to Android development but have a little bit of WPF experience so I thought the XML would be similar. The following is what I would like the view to look like:
This is the XML I currently have to solve this problem:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_guimain"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:weightSum="2"
tools:context="indoorpilot.indoorpilot.GUIMain">
<TableRow>
<!--android:layout_width="match_parent">-->
<TextView
android:id="@+id/textView"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Building Label"/>
</TableRow>
<TableRow>
<RelativeLayout
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/mclaurysecondfloor"
android:id="@+id/imageView2"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/presence_online"
android:="@+id/markerImage"/>
</RelativeLayout>
</TableRow>
<TableRow>
<LinearLayout
android:layout_weight="1"
style="?android:attr/buttonBarStyle">
<Button
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/contextual_info"
android:onClick="ShowContextualInformation"/>
<Button
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/scan_button"
android:onClick="SetRSSIDistanceValues"/>
</LinearLayout>
</TableRow>
</TableLayout>
Which is working fine on a large device (tablet) but it does not show properly in the Android Studio View Renderer OR on a phone of any sorts. The buttons are not shown as the TableRow containing the RelativeLayout ends up taking up the entire screen...
I've done this outside android studio, but may help you, if you need I can edit for you.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_guimain"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:weightSum="2"
tools:context="indoorpilot.indoorpilot.GUIMain">
<TextView
android:id="@+id/textView"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Building Label"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView"
android:layout_above="@+id/buttons_container"
app:srcCompat="@drawable/mclaurysecondfloor"
android:id="@+id/imageView2"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
app:srcCompat="@android:drawable/presence_online"
android:id="@+id/markerImage"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_below="@+id/imageView2"
android:layout_height="wrap_content"
android:layout_orientation="horizontal"
android:id="@+id/buttons_container"
style="?android:attr/buttonBarStyle">
<Button
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/contextual_info"
android:onClick="ShowContextualInformation"/>
<Button
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/scan_button"
android:onClick="SetRSSIDistanceValues"/>
</LinearLayout>
</RelativeLayout>
You don't need a TableLayout
. What you need is a RelativeLayout
that has one TextView
at the top, two ImageView
s below, and a LinearLayout
containing the two buttons at the bottom of your view. You may need a ScrollView
containing this RelativeLayout
for smaller screen sizes.