set layout component to center
here in above screen, i have two linear layouts, one for two TextView and two EditText and other layout for Three Button as shown in figure,
Now I want to set these two layouts as below:
1) The first layout is required to set at the center of the screen
2) The all buttons or second layout have to be set on the bottom of screen
So I want to ask how i can do this.
My XML file is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height开发者_运维问答="fill_parent"
android:orientation="vertical"
android:background="#000044">
<ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content" android:layout_gravity="center">
<TextView android:text="Login Phone" style="@style/TextStyle.Default" android:id="@+id/loginphone"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/login" android:layout_width="match_parent" android:text="" android:inputType="number" android:numeric="integer" android:phoneNumber="true"></EditText>
<TextView android:text="Mobile Pin" android:id="@+id/mobilepin" style="@style/TextStyle.Default"></TextView>
<EditText android:layout_height="wrap_content" android:id="@+id/pin" android:inputType="number" android:numeric="integer" android:layout_width="match_parent" android:text="" android:password="true"></EditText>
</LinearLayout>
</ScrollView>
<LinearLayout android:id="@+id/linearLayout2" android:layout_height="match_parent" android:layout_gravity="bottom" android:layout_width="fill_parent" android:orientation="horizontal" android:gravity="bottom">
<Button android:id="@+id/preference" android:text="Preferences" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
<Button android:id="@+id/loginbutton" android:text="Login" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
<Button android:id="@+id/exit" android:text="Exit" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000044">
<ScrollView
android:id="@+id/scrollView1"
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/linearLayout1"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="Login Phone"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/loginphone" />
<EditText
android:id="@+id/login"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="number"
android:numeric="integer"
android:phoneNumber="true" />
<TextView
android:text="Mobile Pin"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/mobilepin" />
<EditText
android:id="@+id/pin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:numeric="integer"
android:password="true" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearLayout2"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:id="@+id/preference"
android:text="Preferences"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<Button
android:id="@+id/loginbutton"
android:text="Login"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<Button
android:id="@+id/exit"
android:text="Exit"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
</LinearLayout>
change the wrapper layout to a RelativeLayout.
Set the button layout to android:layout_alignParentBottom="true"set the textview layout android:layout_centerInParent="true"
Use the parent layout is the Relative Layout and add your two linear layout inside that relative layout with the property for the center layout android:layout_centerInParent="true" and for button layout android:layout_alignParentBottom="true".
Is is what you wanted?
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/loginphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Phone" >
</TextView>
<EditText
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:numeric="integer"
android:phoneNumber="true"
android:text="" >
</EditText>
<TextView
android:id="@+id/mobilepin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile Pin" >
</TextView>
<EditText
android:id="@+id/pin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:numeric="integer"
android:password="true"
android:text="" >
</EditText>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/preference"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Preferences" >
</Button>
<Button
android:id="@+id/loginbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Login" >
</Button>
<Button
android:id="@+id/exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Exit" >
</Button>
</LinearLayout>
</LinearLayout>
精彩评论