How to fill remaining space in layout? - android

I have these button like shown on the picture below, and I want them to arrange themselve so they begin at the top of the layout and end at the bottom, and also auto arrange space in between. How to do that?
My xml code:
<?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:background="#drawable/background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="360dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="5dp" >
<Button
android:id="#+id/bA1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A1"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bA2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A2"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bA3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A3"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bA4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A4"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bA5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A5"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bA6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A6"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bA7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A7"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bA8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A8"
android:background="#drawable/buttons" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:gravity="top"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="10dp" >
<Button
android:id="#+id/bB1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/buttons"
android:text="B1" />
<Button
android:id="#+id/bB2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="B2"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bB3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="B3"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bB4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="B4"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bB5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="B5"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bB6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="B6"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bB7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="B7"
android:background="#drawable/buttons" />
<Button
android:id="#+id/bB8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="B8"
android:background="#drawable/buttons" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>

Use weight. Some sample code follows.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:padding="48dp"
android:weightSum="4" >
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 1" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 2" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 3" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 4" />
</LinearLayout>
The code android:weightSum="4"will say to use a "weight" of 4, and each child here use 1 of that weight, a procentual value (25%). You could alter the weightSum and the weight of each child and thus giving each child a percentage width or height. Use 0dp to manipulate the dimension.

Try this.. its working for me.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:layout_weight="8" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:weightSum="8" >
<Button
android:id="#+id/bA1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A1" />
<Button
android:id="#+id/bA2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A2" />
<Button
android:id="#+id/bA3"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A3" />
<Button
android:id="#+id/bA4"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A4" />
<Button
android:id="#+id/bA5"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A5" />
<Button
android:id="#+id/bA6"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A6" />
<Button
android:id="#+id/bA7"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A7" />
<Button
android:id="#+id/bA8"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="A8" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:weightSum="8" >
<Button
android:id="#+id/bB1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B1" />
<Button
android:id="#+id/bB2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B2" />
<Button
android:id="#+id/bB3"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B3" />
<Button
android:id="#+id/bB4"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B4" />
<Button
android:id="#+id/bB5"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B5" />
<Button
android:id="#+id/bB6"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B6" />
<Button
android:id="#+id/bB7"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B7" />
<Button
android:id="#+id/bB8"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/dialog_frame"
android:text="B8" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:background="#android:drawable/dark_header"
android:layout_weight="1" />
Now it will look like
As i added Header and Footer also.

Related

Not able to display buttons in the screen

I am having a screen which has many layouts having title,list view ,comment and buttons but buttons are not getting displayed at all,after list view display I am getting a huge amount of empty space after which comment is getting displayed and buttons are not seen ,this is my code.
<?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:background="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_margin="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="12345617890" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:fontFamily="#android:color/black"
android:text="Ramakrisha Tripati" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="9876543210" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_margin="10dp"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="13/1/2015" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Rohit Sharma" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:orientation="horizontal"
android:background="#android:color/holo_orange_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="item#\nstyle#"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M Wt\nD Wt\nCS Wt"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Making\nD Rate\nCS Rate"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Margin\nDis %\nDiscount"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GT\nFSP"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#00000000"
android:dividerHeight="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="Comment" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:ems="10"
android:hint="Comment goes here"
android:inputType="textMultiLine" />
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="accept"
android:src="#drawable/accept"
/>
</LinearLayout>
I have modified your layout code and now the button has appeared.
<?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="#android:color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="12345617890" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:fontFamily="#android:color/black"
android:text="Ramakrisha Tripati" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="9876543210" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="13/1/2015" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Rohit Sharma" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="#android:color/holo_orange_light"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="item#\nstyle#" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="M Wt\nD Wt\nCS Wt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Making\nD Rate\nCS Rate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Margin\nDis %\nDiscount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GT\nFSP" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#00000000"
android:dividerHeight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment"
android:textSize="25dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:ems="10"
android:hint="Comment goes here"
android:inputType="textMultiLine" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:onClick="accept"
android:src="#drawable/accept" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Just put your main LinearLayout inside scrollview and you will see thr buttons.
And if not so maybe your image is so small or transparent.
check with another image maybe.

Position of the elements in Android XML file

I have a question regarding how to position elements in a XML file for an android activity.
What i need to achieve is the following:
Basically i need:
a set of 9 squares (3x3 table) covering 50% of the screen height
on the second part of the screen, 3 equally distributed zones with a single textview / button for each.
i created the set of 9 squares using a tableview with this code:
<TableLayout
android:layout_width="match_parent"
android:layout_height="386dp"
android:stretchColumns="*" >
<TableRow
android:id="#+id/Row1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/square1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
<Button
android:id="#+id/square2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="3"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
<Button
android:id="#+id/square3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="3"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
</TableRow>
<TableRow
android:id="#+id/Row2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/square4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
<Button
android:id="#+id/square5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
<Button
android:id="#+id/square6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
</TableRow>
<TableRow
android:id="#+id/Row3"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/square7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
<Button
android:id="#+id/square8"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="2"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
<Button
android:id="#+id/square9"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="3"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="60sp" />
</TableRow>
</TableLayout>
This part is included in a relative layout.
Now i can't get in any way to set this part to be 50% of the screen, and add a second 50% with the 3 buttons.
Hope you can help me. I searched here for answers but didn't find any relevant topic
Here you go:
<TableLayout 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" >
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:text="1"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
<Button
android:text="2"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
<Button
android:text="3"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:text="4"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
<Button
android:text="5"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
<Button
android:text="6"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:text="7"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
<Button
android:text="8"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
<Button
android:text="9"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:text="10"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:text="11"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:text="12"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
/>
</TableRow>
Use LinearLayout instead of RelativeLayout and use android:weight attribute to achieve 50% screen height as follows...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_wieght="1" >
..............
..............
</TableLayout>
<!-- Other other layout which will take android:layout_wieght="1" -->
</LinearLayout>
This will be a very simple answer to this question only using LinearLayout :
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="one part"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="one part"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="one part"/>
</LinearLayout>
</LinearLayout>

How can I anchor 4 linear layouts to the bottom of a linear layout?

As you can see here, I have created 4 linear layouts circled with yellow, green, blue, and purple to distinguish between the different horizontals. I would like to anchor all 4 of these layouts to the bottom of the main linear layout as shown in red. I was looking for the easiest solution to my problem. Perhaps a RelativeLayout for the main layout, but then how would I get all 4 linear layouts to anchor to the bottom and stacked on top of each other in this order? Sorry for not posting code, but the code for all the buttons would probably be too long.
<?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="wrap_content"
android:background="#drawable/po"
android:orientation="vertical" >
<EditText
android:id="#+id/txtQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
/>
<Button
android:id="#+id/btnClear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Clear"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill_vertical"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:weightSum="10" >
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Q" />
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="W"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="E"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="R"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="T"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Y"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="U"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="I"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="O"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="P"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="9" >
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="A" />
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="S"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="D"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="F"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="G"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="H"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="J"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="K"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="L"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10" >
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Z" />
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="X"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="C"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="V"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="B"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="N"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="M"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=","
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="."
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="\?"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="bottom|center"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:layout_weight="25"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Space"
/>
<Button
android:layout_weight="75"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Bkspc"
/>
</LinearLayout>
</LinearLayout>
You need to create your xml in following way.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/ic_launcher"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/txtQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<Button
android:id="#+id/btnClear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Clear"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout android:gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_below="#+id/linear"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="fill_vertical"
android:orientation="horizontal"
android:weightSum="10" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Q" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="W" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="E" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="R" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="T" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Y" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="U" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="I" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="O" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="P" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="9" >
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="A" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="S" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="D" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="F" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="G" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="H" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="J" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="K" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="L" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10" >
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Z" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="X" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="C" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="V" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="B" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="N" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="M" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="," />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="." />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="\?" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="bottom|center"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="25"
android:text="Space" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="75"
android:text="Bkspc" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
OUTOUT :
Use RelativeLayout as the parent Layout.Then Use alignParentBottom property to set All the layouts at the bottom.

layout buttons are not the same size in android

I have two questions, the first is that I would like the buttons to be on the bottom corner of the screen stacked like they are (they currently are in the middle) and I would like them to be the same size, currently the top 2 buttons are bigger then the bottom two buttons. Also maybe lowering the texview boxes down a little if that is easy enough.
<?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="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/badd1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+1" />
<Button
android:id="#+id/badd5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/bsub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/bsub5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2add1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+1" />
<Button
android:id="#+id/b2add5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2sub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/b2sub5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Check now.
<?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="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/badd1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+1" />
<Button
android:id="#+id/badd5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/bsub1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/bsub5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:layout_width="156dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2add1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+1" />
<Button
android:id="#+id/b2add5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2sub1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/b2sub5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
All buttons should look like this one.-
<Button
android:id="#+id/badd5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+5" />
Check layout_width and layout_weight properties.
As for the EditTexts, you have several options, an easy one would be applying some top margin.-
<EditText
android:id="#+id/playerLifeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" >
just a tip: using a RelativeLayout would give you more flexibility and a more simple possibility to achieve what you need.
Note: in my sample project the Holo.Light theme is applied, that's why it looks a bit different.
<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"
tools:context=".MainActivity" >
<!-- this is a SAMPLE layout. Adjust the values as you need them. -->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="#000000"
android:orientation="vertical" >
</LinearLayout>
<EditText
android:id="#+id/editText1"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:ems="10" >
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:ems="10" >
<requestFocus />
</EditText>
<!-- do the same thing on the right side -->
<Button
android:id="#+id/btnMinOneLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="-1" />
<Button
android:id="#+id/btnMinFiveLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/btnMinOneLeft"
android:text="-5" />
<Button
android:id="#+id/btnPlusOneLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_above="#+id/btnMinOneLeft"
android:layout_alignParentLeft="true"
android:text="+1" />
<Button
android:id="#+id/btnPlusFiveLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_above="#+id/btnMinFiveLeft"
android:text="+5"
android:layout_toRightOf="#+id/btnPlusOneLeft"/>

Evenly spaced out row of buttons required

Using 3 rows and 4 columns I have tried to evenly space out all the buttons horizontally but have failed. vertically is fine.
Below are 3 different attempts to space out the buttons, 1 for each of my 3 rows. The first row stretches the graphic (which is unwanted), the second row does not stretch but there is no spacing (spacing between the graphics is required), while the third stretches without any spacing. Please help me to evenly space these out. Other peoples solutions on this same site have not worked. Should I try using a table instead?
Visual summary= without stretching the graphic:
I want | x x x x |
and not | xxxx |
<?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" >
<LinearLayout
android:id="#+id/row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight=".1" >
</View>
<Button
android:id="#+id/a1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/clear64" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight=".1" >
</View>
<Button
android:id="#+id/a2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/clear64" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight=".1" >
</View>
<Button
android:id="#+id/a3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/clear64" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight=".1" >
</View>
<Button
android:id="#+id/a4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/clear64" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight=".1" >
</View>
</LinearLayout>
<LinearLayout
android:id="#+id/row2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center"
android:src="#drawable/clear64" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center"
android:src="#drawable/clear64" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center"
android:src="#drawable/clear64" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/blanktilesml"
android:gravity="center"
android:src="#drawable/clear64" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/row3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/c1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:background="#drawable/blanktilesml"
android:paddingLeft="10dp"
android:src="#drawable/clear64" />
<Button
android:id="#+id/c2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:background="#drawable/blanktilesml"
android:paddingLeft="10dp"
android:src="#drawable/clear64" />
<Button
android:id="#+id/c3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:background="#drawable/blanktilesml"
android:paddingLeft="10dp"
android:src="#drawable/clear64" />
<Button
android:id="#+id/c4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:background="#drawable/blanktilesml"
android:paddingLeft="10dp"
android:src="#drawable/clear64" />
</LinearLayout>
</LinearLayout>
Try this:
<LinearLayout
android:id="#+id/row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/a1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/arrow_up_float"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/a2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/arrow_up_float"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/a3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/arrow_up_float"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/a4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/arrow_up_float"
android:gravity="center_horizontal|center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
try this for your first row. Similarly can be done for all the row,
So unless you don't want the images to be stretched you need to rap them in a layout. Doing so you will manage the spacing and the drawable will look just fine. If you stretch the buttons then the drawable will also be stretched accordingly.
Here is what I did with a calculator project I was working on. Requiring buttons in rows all the same size. You will need to add padding to your buttons to suit your needs.:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:id="#+id/NumberPad">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/NumberRow123"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/button1"
android:layout_weight="1"
android:background="#drawable/unpressed7"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/button2"
android:layout_weight="1"
android:background="#drawable/unpressed8"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/button3"
android:layout_weight="1"
android:background="#drawable/unpressed9"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/NumerRow456"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/button4"
android:layout_weight="1"
android:background="#drawable/unpressed4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/button5"
android:layout_weight="1"
android:background="#drawable/unpressed5"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/button6"
android:layout_weight="1"
android:background="#drawable/unpressed6"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/NumberRow789">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button7"
android:layout_weight="1"
android:background="#drawable/unpressed1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/button8"
android:layout_weight="1"
android:background="#drawable/unpressed2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/button9"
android:layout_weight="1"
android:background="#drawable/unpressed3"/>
</LinearLayout>

Categories

Resources