Say I wanted to list buttons so that the last one was anchored to the bottom of the screen, how would I go about this. From my understanding, LinearLayout will give me the 'list' of buttons but it will be anchored to the top. RelativeLayout, on the other hand, will allow me to anchor to the bottom but each and every element will have to have a reference to the next element and the XML file will be in reverse order (so that references are valid).
How should I approach this?
EDIT: Apologies, this would be roughly what I would be looking for -
i have a hard time understanding your question exactly. But i assume that what you want is a horizontal list of buttons which is anchored to the bottom of the screen?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- put your other views in here -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="cancel" />
<Button
android:id="@+id/button_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="ok" />
</LinearLayout>
</LinearLayout>
You can try adding an extra LinearLayout with a weight of 1 to take up all of the remaining space, and push the list of buttons to the bottom of the Activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<Button
android:id="@+id/widget33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Sample XML is for a single button that gets pushed by a LinearLayout to the bottom of the Activity; root layout is Linear too.
RelativeLayout
Konayuki 2017-02-02 08:26