How to align linearlayout to vertical center? - android

I'm trying to align LinearLayout's vertical center which shows following pic (skycolor border) to delete button's vertical center.
so I set the gravity of id:groupNumbers to center_vertical.
but no changed.
How to align id:groupNumbers to button's center?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/groupNumbers"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_weight="0.7"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtSelected01"
android:text="00"
android:textSize="30dp"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtSelected02"
android:text="00"
android:textSize="30dp"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btn_deleteNum"
android:text="Delete"
android:textSize="20dp"
android:layout_weight="0.2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

Change orientation and gravity in
<LinearLayout
android:id="#+id/groupNumbers"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_weight="0.7"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
to
android:orientation="vertical"
android:layout_gravity="center_vertical"
You are adding orientation: horizontal, so the layout will contain all elements in single horizontal line. Which won't allow you to get the element in center.

use android:layout_gravity instead of android:gravity
android:gravity sets the gravity of the content of the View its used on.
android:layout_gravity sets the gravity of the View or Layout in its parent.

Use layout_gravity instead of gravity. layout_gravity tells the parent where it should be positioned, and gravity tells its child where they should be positioned.
<LinearLayout
android:id="#+id/groupNumbers"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:layout_weight="0.7"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

For me, I have fixed the problem using android:layout_centerVertical="true" in a parent RelativeLayout:
<RelativeLayout ... >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true">
</RelativeLayout>

For a box that appears in the center - horizontal & vertical - I got this to work with just one LinearLayout. The answer from Viswanath L was very helpful
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/layout_bg"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:id="#+id/dialog_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="Error"
android:textColor="#000" />
<TextView
android:id="#+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="Error-Message"
android:textColor="#000" />
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/message_text"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="Ok" />
</LinearLayout>

use RelativeLayout inside LinearLayout
example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Status"/>
</RelativeLayout>
</LinearLayout>

Use android:weightSum property to the parent LinearLayout and give value 3. Then in the children LinearLayout use android:layout_weight 2 and 1 respectively. Then in the First Chil LinearLayout use android:layout_gravity="center_vertical". As shown in the following code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textColor="#color/red"
android:textSize="#dimen/default_text_size"
/>
<TextView
android:id="#+id/status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textColor="#color/red"
android:textSize="#dimen/default_text_size"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Delete"/>
</LinearLayout>
</LinearLayout>

You can change set orientation of linearlayout programmatically by:
LinearLayout linearLayout =new linearLayout(this);//just to give the clarity
linearLayout.setOrientation(LinearLayout.VERTICAL);

Related

Set textview below another textview in horizontal linear layout

How to set TextView object tvOperationDesc below tvOperationName
This is my layout xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvOperationName"
android:layout_width="0sp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center_vertical"
/>
<TextView
android:id="#+id/tvOperationDesc"
android:layout_width="0sp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center_vertical"
android:layout_below="#+id/tvOperationName"
/>
<EditText
android:id="#+id/txtMultiplier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:inputType="numberDecimal"
android:text="0"
android:textAppearance="?android:attr/textAppearanceSmall" />
<CheckBox
android:id="#+id/cbChkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Use 2 separate horizontal linear layouts in your relative layout and you can adjust the weights and the heights as you like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<LinearLayout
android:id="#+id/upLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="#+id/tvOperationName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" />
<EditText
android:id="#+id/txtMultiplier"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:inputType="numberDecimal"
android:text="0"
android:textAppearance="?android:attr/textAppearanceSmall" />
<CheckBox
android:id="#+id/cbChkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/upLayout">
<TextView
android:id="#+id/tvOperationDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"/>
</LinearLayout>
</RelativeLayout>
Textview below textview in horizontal linear layout
Not possible at all. Its clearly mentioned horizontal linear layout. So, you views are aligned horizontally only.
Then
If you set your linear layout orientation to horizontal your views are aligned horizontally & orientation to vertical your views are aligned vertically in linear manner that means one by one.
Solution
One relative layout is enough for your requirements. Have a look at my answer How relative layout views are aligned will help you.
Please try below code.
<TextView
android:id="#+id/tvOperationDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Description" />
<LinearLayout
android:id="#+id/secondLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvOperationName"
android:layout_width="0sp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center_vertical"
android:text="Name" />
<EditText
android:id="#+id/txtMultiplier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:inputType="numberDecimal"
android:text="0"
android:textAppearance="?android:attr/textAppearanceSmall" />
<CheckBox
android:id="#+id/cbChkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
if you want EditText and Checkbox in the same line as tvOperationName vertically just change orientation of secondLinearLayout to vertical and give gravity="center_horizontal" to secondLinearLayout.
Add another LinearLayout with orientation to vertical, and place both the TextView.
And remove layout_below property inside LinearLayout’s child view, as its useless.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvOperationName"
android:layout_width="0sp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center_vertical"
/>
<TextView
android:id="#+id/tvOperationDesc"
android:layout_width="0sp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center_vertical"
android:layout_below="#+id/tvOperationName"
/>
</LinearLayout>

Why does my Listview show large spaces even it has little text?

In some ListView's holder I got empty spaces even it has a small text in it.
TextView is set to wrap_content. My listview layout xml item has several buttons. I just set these buttons VISIBILITY.GONE.
<?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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textView"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="photo"
android:id="#+id/photo"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:baselineAligned="false"
android:clickable="false"
android:focusable="false">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="New Button"
android:id="#+id/left" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="New Button"
android:id="#+id/right" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:baselineAligned="false"
android:clickable="false"
android:focusable="false" >
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_gravity="center_horizontal"
android:layout_weight="4"
android:gravity="center_horizontal"
android:hint="#string/answer"
android:maxLength="4" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/ok"
android:id="#+id/ok" />
</LinearLayout>
</LinearLayout>
Put the root as wrap_content instead of match_parent for the height.
What will happen in a vertically scrolling listview (read, infinite height available for children) if it's children say they want match_parent?
Can't see your image, but in a RecyclerView, each item's height would be the height of the RecyclerView.
Instead of using "match_parent" in the top use "wrap_content" for height

Align checkbox to the right side in LinearLayout android

I am trying to make some text views with checkboxes in LinearLayout. I want for result like this:
TextView Ckeckbox
TextViewwwwww Ckeckbox
TextV Ckeckbox
But currently I have this:
TextView Checkbox
TextViewwwww Checkbox
TextView Checkbox
Here is my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</LinearLayout>
And this xml gives me same result:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"/>
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"/>
</LinearLayout>
You can use the layout_weight attribute on your TextView only to automatically designate the TextView to fill any space which the CheckBox does not occupy. For example, the following will set your checkboxes to the end (provided they have no text associated with them) and then lets the TextView fill the rest of the layout.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<TextView
android:id="#+id/itemTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Additionally, you should use match_parent instead of fill_parent as fill_parent is deprecated.
Try 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:orientation="vertical"
tools:context="com.example.ipdemo.MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Use layout weights and try this:
<?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:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="5">
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="wdjhwdjwo"/>
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"/>
</LinearLayout>
You should be using layout_weight attribute to achieve the effect
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
So horizontally both the views will be occupying half of the screen size. You could adjust layout_weight to achieve the desired outcome.
There maybe other ways to do this, but I think this method is the best way.
Use layout_gravity="right" instead of gravity="end" if you're working with vertical layouts.
Your CheckBox tag should look like:
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"/>
EDIT: On horizontal layouts, try layout_weight="1", that will make both of your elements fill half of the layout space.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<CheckBox
android:id="#+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
check the following use android:layout_weight="1" in both view
<?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:layout_alignParentTop="true"
android:orientation="horizontal">
<TextView
android:id="#+id/itemTitle"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
<CheckBox
android:id="#+id/checkItem"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
</LinearLayout>

Android layout issue with sibling of RelativeLayout

I add add LinearLayout with horizontal orientation to my Android layout, but unfortunately there is an error: id/title_dialog_text_view is not a sibling in the same RelativeLayout.
I am trying to combine TextView and ProgressBar in horizontal not vertical line.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/title_dialog_text_view"
android:layout_marginTop="6dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:paddingBottom="20dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/title_dialog_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text=""
android:textSize="18sp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ProgressBar
android:id="#+id/pb_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"/>
<TextView
android:id="#+id/text_dialog_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:layout_margin="20dp"
android:lineSpacingExtra="6dp"
android:text=""
android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
this error is because parent of TextView and LinearLayout are not same.
if you want to put TextView and ProgressBar horizontal , change their parent's orientation to horizontal
May this solves your problem :
<ProgressBar
android:id="#+id/pb_loading"
style="#android:style/Widget.ProgressBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp" />
<TextView
android:id="#+id/text_dialog_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text=""
android:textSize="16sp" />

Can't add margins to RadioButtons

I have a problem with my layout. I have a Dialog in which I would like to put RadioButtons, but as you can see on the screenshot they are really close to each other. How to widen the space between them? I've already tried Margin Left/Right, Padding Left/Right, etc, but none of this works.
Screenshot
My .xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/backrepeat_reversed" >
<TextView android:id="#+id/ml_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/size"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup android:id="#+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<RadioButton android:id="#+id/rws"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="#null"
android:text="#string/sw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
<RadioButton android:id="#+id/rwm"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="#null"
android:text="#string/mw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
<RadioButton android:id="#+id/rwb"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="#null"
android:text="#string/bw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</RadioGroup>
</LinearLayout>
<TextView android:id="#+id/percent_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/percentage"
android:gravity="center"/>
<NumberPicker
android:id="#+id/percent_picker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
The radio buttons are placed side-by-side in a LinearLayout. They have their layout_width set to wrap_content. The parent (the RadioGroup) is also set to wrap_content, and its two parents (LinearLayout, and its parent, the root LinearLayout element) are also set to wrap_content. The gravity is also set to be centred, so everything is gravitating towards the centre for the screen, and remains huddled together.
Try:
set the root LinearLayout element's layout_width to be fill_parent.
Set the nested LinearLayout (parent of RadioGroup) to be a RelativeLayout (i.e. change the element type)
Set for each RadioButton, the width to be 33% by adding this attribute/value pair: android:layout_weight=".33"
Use LinearLayout or other Layout to Optimize the layout. You can do it like below:
<?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/backrepeat_reversed" >
<TextView android:id="#+id/ml_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/size"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup android:id="#+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="#+id/rws"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="#null"
android:text="#string/sw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="#+id/rwm"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="#null"
android:text="#string/mw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="#+id/rwb"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="#null"
android:text="#string/bw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
</RadioGroup>
</LinearLayout>
<TextView android:id="#+id/percent_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/percentage"
android:gravity="center"/>
<NumberPicker
android:id="#+id/percent_picker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
Try it, I think it helps.

Categories

Resources