Android: 5 buttons location: a better way?
I want to fix five buttons, as shown in the picture. But I put five buttons in the position of nexus 6. When I tried this code on nexus 10, I realized that I wasted an hour: all buttons are in different positions!
What is the best way to fix five buttons? All devices / screens can fix all positions
Does the following layout work?
RelativeLayout
Linear1 ( for the first 2 buttons )
Linear 2 ( for the 2 buttons next buttons )
Linear 3 ( for the last button )
/RelativeLayout
I repeat my question because I don't know: how to place a button in a specific position? For example, I want to place my green button at 70% of the top of the screen and 50% of the right / left of the screen
resolvent:
Try associating relativelayout with Android: layout_ alignParentTop,android:layout_ Centervertical is used together with other similar alignment attributes. They enable you to place buttons specifically in the layout to achieve the desired effect. The results are as follows:
This is the code:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.yourpackage.FiveButtonActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:id="@+id/button1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
android:id="@+id/button2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3"
android:id="@+id/button3"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4"
android:id="@+id/button4"
android:layout_alignBottom="@+id/button5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5"
android:id="@+id/button5"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>