Reputation: 1
Is there a way to put buttons in a linear layout with self aligned spaces? I've been using relative layout, but the problem is that my screen does not remain responsive, so how do I make it responsive while using relative layout? Or else how can I add spaces in linear layout and place my buttons according to my height and width?
These are the output with both relative and linear layout. I've tried a lot by using different linear layouts, but it doesn't help as well.
this is the output with relative layout,but it is not responsive
this is output with linear layout, where spaces are not being added by me
Upvotes: 0
Views: 412
Reputation: 4422
You can try something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Button One" />
<android.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Button Two" />
<android.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Button Three" />
<android.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Button Four" />
<android.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Button Five" />
<android.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Taller Screen:
Shorter Screen:
Upvotes: 1