How to align the two views with equal width in android? - android

Can we use single linear layout or other equivalent layout to display the view as per below image view order.

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="50" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="FirstName"/>
<EditText
android:id="#+id/edi1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter First Name"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="50" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="LastName" />
<EditText
android:id="#+id/edi2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Last Name"/>
<Button
android:id="#+id/button1"
android:text="Click Me"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
use the above code

This will give you what you want and conform to material design guidelines:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout android:layout_width="0dp"
android:layout_weight="1"
android:hint="Firstname"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout android:layout_width="0dp"
android:layout_weight="1"
android:hint="Lastname"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
You'll need to add compile 'com.android.support:design:23.1.1' to your app's build.gradle file.

The below code show that how you can do this:
<LinearLayout 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:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Firstname" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Enter your firstname..." />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi"
android:layout_gravity="left"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bye"
android:layout_gravity="right"></Button>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Lastname" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Enter your lastname..." />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="goodbye"
android:layout_gravity="right"/>
</LinearLayout>
</LinearLayout>
Important:This code only show you how to use layout_weight and layout_gravity.

Related

Android - row of buttons at bottom disappears (not in designer)

The app has a screen that needs at the bottom a button bar. Above are a few text views and 1 editview.
When the user starts editing, the software keyboard becomes visible. I would like the buttons to move up and always be visible. The rest of the views should shrink.
Normally I would expect the below code to work. I tried many options, e.g. with a RelativeLayout as top layout manager.
==> The result is that the button bar is gone!
When I remove the Scrollview, then the buttons bar is visible again.
Why does the button bar disappear? In the designer it is visible.
My first series of attempts (that I use in other screens) uses a RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="horizontal" >
<ScrollView
android:id="#+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_above="#id/bottom_buttons"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="#+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text />
</LinearLayout>
<TextView
android:id="#+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:layout_alignParentBottom="true"
android:id="#+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button ... 2>
<Button ... 3>
</LinearLayout>
</RelativeLayout>
In my AndroidManifest.xml I use normally:
<activity
android:name="xy.organisation.app.MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation" >
My second series of attempts is using a LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="#+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text />
</LinearLayout>
<TextView
android:id="#+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:orientation="horizontal">
<Button
android:id="#+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button ... 2>
<Button ... 3>
</LinearLayout>
</LinearLayout>
You have given weight 0 to the linear layout of the buttons. Removing that will fix the issue. Also add 0dp height to ScrollView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="#+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text />
</LinearLayout>
<TextView
android:id="#+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button ... 2>
<Button ... 3>
</LinearLayout>
Relative Layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_buttons"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold"/>
<EditText
android:id="#+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text=""/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text"/>
</LinearLayout>
<TextView
android:id="#+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text=""/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_alignParentBottom="true"
android:id="#+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"/>
<Button
android:id="#+id/save_button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"/>
<Button
android:id="#+id/save_button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"/>
</LinearLayout>
I tried your code:
Below code is working fine:--
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="horizontal"
tools:context=".RelativeActivity"
android:fillViewport="true">
<ScrollView
android:id="#+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="#+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text" />
</LinearLayout>
<TextView
android:id="#+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:orientation="horizontal">
<Button
android:id="#+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save1" />
<Button
android:id="#+id/save_button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save2" />
<Button
android:id="#+id/save_button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save3" />
</LinearLayout>
</LinearLayout>
Please check your AndroidManifest.xml.
If there is android:windowSoftInputMode="adjustPan" under your activity like below:
<activity android:name=".RelativeActivity"
android:windowSoftInputMode="adjustPan"/>
Remove android:windowSoftInputMode="adjustPan" from AndroidManifest file under your activity. Because of adjustPan your bottom buttons are disappear when keyboard is open.
I hope its work for you.

How do i design this screen in android?

How can i create this Layout in android studio? I try to write some codes but i can' t complete that. Thank you for helps. Should i use LinearLayout or RelativeLayout or TableLayout for same viewing for all devices.
http://i.imgur.com/EBd3CAo.png
<?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:weightSum="1"
android:background="#404040">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="59dp"
android:orientation="horizontal"
android:weightSum="1">
<EditText
android:layout_width="198dp"
android:id="#+id/editText"
android:layout_above="#+id/tv1"
android:layout_marginBottom="31dp"
android:text="12345678901"
android:autoText="false"
android:elegantTextHeight="false"
android:maxLength="11"
android:singleLine="true"
android:background="#000000"
android:textColor="#a0a0a0"
android:inputType="number"
android:textSize="40dp"
android:textAlignment="center"
android:textStyle="bold"
android:layout_height="50dp"
android:layout_weight="0.45" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="tv1"
android:id="#+id/tv1"
android:layout_weight="0.36"
android:textColor="#55ff1c"
android:paddingLeft="10dp" />
</LinearLayout>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bla bla bla bla bla"
android:id="#+id/cbx1"
android:checked="false"
android:singleLine="true"
android:textSize="18dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="180dp"
android:layout_height="wrap_content"
android:id="#+id/listView" />
<LinearLayout
android:orientation="vertical"
android:layout_width="180dp"
android:layout_height="wrap_content">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"></RadioGroup>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Change margin/padding/fontsize/color as required
<?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:background="#404040"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_above="#+id/tv1"
android:autoText="false"
android:background="#000000"
android:elegantTextHeight="false"
android:inputType="number"
android:maxLength="11"
android:singleLine="true"
android:text="12345678901"
android:textAlignment="center"
android:textColor="#a0a0a0"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="tv1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#55ff1c" />
</LinearLayout>
<CheckBox
android:id="#+id/cbx1"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:singleLine="true"
android:text="bla bla bla bla bla"
android:textSize="18dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="2.8"
android:layout_margin="10dp"
android:layout_height="0dp"
android:orientation="horizontal">
<ListView
android:id="#+id/listView"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton1"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton2"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"
android:text="Text View" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"
android:text="Text View" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:padding="5dp"
android:text="button" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_weight="0.2"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:text="Bottomtextview"/>
</LinearLayout>
I made a design as you need. But you may need to set height and width by your own. take a look to the below code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="Edit Text" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Text View" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check Box" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ListView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button" />
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Text View"
android:textSize="24sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:text="Text View" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="10dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text View"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
I designed this by linear layout. hope it helps you.

Make the control in LinearLayout not to fill all the space

I have a layout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fsfsdfds"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fdsfdsfds"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
It fill the whole space of the activity.
How can I make these 2 TextViews and EditTexts take only space enough to show themselves (not fill all the space) and align the button to the bottom?
I think this is what you're looking for :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView1" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/LinearLayout1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView2" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:inputType="text" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" />
</RelativeLayout>
EDIT :
If you don't want to use the two LinerLayouts (and therefore gain even more performance), you can do the following :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/EditText1"
android:layout_gravity="center_vertical"
android:text="TextView1" />
<EditText
android:id="#+id/EditText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:layout_toEndOf="#id/TextView1"
android:layout_toRightOf="#id/TextView1"
android:inputType="text" />
<TextView
android:id="#+id/TextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/EditText2"
android:layout_below="#id/TextView1"
android:layout_gravity="center_vertical"
android:text="TextView2" />
<EditText
android:id="#+id/EditText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/EditText1"
android:layout_gravity="center_vertical"
android:layout_toEndOf="#id/TextView2"
android:layout_toRightOf="#id/TextView2"
android:inputType="text" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" />
</RelativeLayout>
Check This.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:text="fsfsdfds" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:text="fdsfdsfds" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
You try with RelativeLayout, or else if wanted to be done with LinearLayout you need to consider weights if width is not fillparent.
Check below sample to start with ..
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:text="fsfsdfds" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.8" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:text="fdsfdsfds" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.8" />
Either convert to a relative-layout and use alignparentbottom for the button - or use layout weights for the linear-layouts

scrollable layout not working

I'm a beginner in android. I'm creating a example phonebook using eclipse. i have few edit texts and a set off buttons in my layout.but when I run the project I can't see the buttons in the bottom of the layout, so I enclosed my main linear layout in a Scrollview. but after linear layout has become much bigger in height. i tried to resize it in the xml file but it is not working right after resizing the layout it automatically resizes in to the previous size. here's my code if anyone can help me.little help is highly appreciated.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="466dp"
android:layout_gravity="center_vertical" >
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back"
android:orientation="vertical"
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:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"
tools:context="com.nadusha.phonebook.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Info"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/nameTextLayout"
android:orientation="horizontal"
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/mobileNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/homeNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-Mail "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/emailTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/saveBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:textColor="#FFFFFF"/>
<Button
android:id="#+id/cancelBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/viewBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ViewContact"
android:textColor="#FFFFFF" />
</Linearlayout>
</LinearLayout>
You need to set ScrollView layoutWeight to 1 and its height to 0. This will ensure that your scrollview will take only remaining space on screen. Here is example of my app:
<?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"
>
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clickable="false"
android:fadeScrollbars="false"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/menoLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSMeno"/>
<EditText
android:id="#+id/menoEdit"
style="#style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#000"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="3">
<TextView
android:id="#+id/pohlavieLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSPohlavie"/>
<Spinner
android:id="#+id/spinnerPohlavie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/vekLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSVek"/>
<EditText
android:id="#+id/vekEdit"
style="#style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"
android:textColor="#000"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/vahaLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSVaha"/>
<EditText
android:id="#+id/vahaEdit"
style="#style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"
android:textColor="#000"/>
</LinearLayout>
<TextView
android:id="#+id/alergieLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSAlergie"/>
<EditText
android:id="#+id/alergieEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="#000"/>
<TextView
android:id="#+id/chorobyLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSChoroby"/>
<EditText
android:id="#+id/chorobyEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="#000"/>
<TextView
android:id="#+id/zraneniaLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSZranenie"/>
<EditText
android:id="#+id/zraneniaEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:lines="3"
android:textColor="#000"/>
<TextView
android:id="#+id/polohaLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSAktualnaPoloha"/>
<EditText
android:id="#+id/polohaEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="#000"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="#+id/odoslatButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/send"
android:layout_weight="1"/>
<Button
android:id="#+id/zrusitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/emergencySMSZrusit"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
It shows scrollView and two buttons bellow it. I am not exactly sure what you want to do but as far as I can see you are doint it wrong. ScrollView can take only one child element but you have set scrollview as your main parent but then you put more child inside it.
Also you are doing another mistake. You dont need to use linear layouts (in most cases) if they have only one child. It is bad for performance.
Change the value of the attribute layout_height to match_parent so that the ScrollView take up the whole screen and hence enable scrolling. The correct code is
<ScrollView 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:layout_gravity="center_vertical" >
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back"
android:orientation="vertical"
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:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"
tools:context="com.nadusha.phonebook.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Info"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/nameTextLayout"
android:orientation="horizontal"
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/mobileNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/homeNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-Mail "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/emailTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/saveBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:textColor="#FFFFFF"/>
<Button
android:id="#+id/cancelBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/viewBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ViewContact"
android:textColor="#FFFFFF" />
</Linearlayout>
</LinearLayout>
You could try changing
android:layout_height="466dp"
to
android:layout_height="wrap_content"
or
android:layout_height="match_parent"

How to position a login box centered on application start?

I am new to Android and trying to build a login box, and experience some troubles. I created two textes (Username, Password) and two text-boxes next to them, to style a login box area.
But unfortunately the elements jump up and down in correlation with the upper and lower bars, that are shown when the user touches the screen.
How can I realize a centered login box?
Link: maximize image
Here is some code:
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout android:id="#+id/fullscreen_content_controls"
style="?buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/login_button" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:baselineAligned="false"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="false"
android:layout_alignParentBottom="false"
android:layout_centerInParent="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_username"
android:id="#+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_password"
android:id="#+id/textView2"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_column="1" />
</TableRow>
</TableLayout>
</RelativeLayout>
</FrameLayout>
There is no need of Table Layout It simply done with relative and linearlayout.
http://www.androidhive.info/2011/10/android-login-and-registration-screen-design/
Use this -
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_username"
android:id="#+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_password"
android:id="#+id/textView2"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_column="1" />
</TableRow>
</TableLayout>
</RelativeLayout>
<Button
android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:text="#string/login_button" />
</FrameLayout>
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_username"
android:id="#+id/textView" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:id="#+id/editText"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_password"
android:id="#+id/textView2"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textPassword"
android:ems="10"
android:layout_marginLeft="5dp"
android:id="#+id/editText3"/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:id="#+id/fullscreen_content_controls"
style="?buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/black_overlay">
<Button android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_button" />
</LinearLayout>
</LinearLayout>

Categories

Resources