Android RelativeLayout : Placing buttons side by side next to one another - android

I am trying to place buttons side by side next to one another in three buttons to one row using a RelativeLayout.
This is the relative layout placed inside a linear layout with the group of buttons
main.xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CC8FD8D8"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="20px" >
</RelativeLayout>
</LinearLayout>
These are the group of button found inside the layouts
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/snap"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/shutterButton"
android:text="SNAP"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/up"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/Up"
android:text="xxxx"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_action_borrow"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/xxxx"
android:text="xxxxx"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/xxxx"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/xxxx"
android:text="xxxx"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/xxxx"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/xxxx"
android:text="xxxx"></Button>
OUTPUT
Please how can I place the buttons one after another in 3 buttons to one row.
Kindly assist!

Try this:
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CC8FD8D8"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="20px">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:text="SNAP"
android:textColor="#FFFFFF"></Button>
<!--android:drawableTop="#drawable/snap"-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:text="xxxx"
android:textColor="#FFFFFF"></Button>
<Button
android:id="#+id/xxxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:text="xxxxx"
android:textColor="#FFFFFF"></Button>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CC8FD8D8"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="20px">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:text="xxxx"
android:textColor="#FFFFFF"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:text="xxxx"
android:textColor="#FFFFFF"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:text="xxxx"
android:textColor="#FFFFFF"
android:visibility="invisible"></Button>
</LinearLayout>
</LinearLayout>
Output will be:

the following code creates 4 buttons side by side horizontally
<LinearLayout
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:id="#+id/lay"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/button1"
android:text="Button1"
android:layout_weight="1"
android:padding="5dp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/button2"
android:text="Button2"
android:layout_weight="1"
android:padding="5dp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/button3"
android:text="Button3"
android:layout_weight="1"
android:padding="5dp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/button4"
android:text="Button4"
android:layout_weight="1"
android:padding="5dp" />
</LinearLayout>

You should linear layout for this kind of horizontal buttons and don't forget to make the orientation of inside LinearLayout to horizontal.
Like
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CC8FD8D8"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="20px" >
Then add buttons inside this linear layout, all the buttons will come side by side.

Try LinearLayout with android:orientation="horizontal". Check this 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:background="#CC8FD8D8"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="20px">
<Button
android:id="#+id/shutterButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:drawableTop="#drawable/snap"
android:text="SNAP"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/Up"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:drawableTop="#drawable/up"
android:text="xxxx"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/xxxx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:drawableTop="#drawable/ic_action_borrow"
android:text="xxxxx"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/xxxx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:drawableTop="#drawable/xxxx"
android:text="xxxx"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/xxxx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FFFFFF"
android:drawableTop="#drawable/xxxx"
android:text="xxxx"
android:textColor="#FFFFFF" />
</LinearLayout>

Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CC8FD8D8"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="20px" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/snap"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/shutterButton"
android:text="SNAP"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/up"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/Up"
android:text="xxxx"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/xxxxx"
android:layout_toStartOf="#+id/xxxxx"
android:layout_marginRight="27dp"
android:layout_marginEnd="27dp"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_action_borrow"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/xxxxx"
android:text="xxxxx"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/xxxx"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/xxxxxx"
android:text="xxxx"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/xxxx"
android:layout_toStartOf="#+id/xxxx"
android:layout_marginRight="50dp"
android:layout_marginEnd="50dp"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/xxxx"
android:textColor="#FFFFFF"
android:background="#00FFFFFF"
android:id="#+id/xxxx"
android:text="xxxx"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"></Button>
</RelativeLayout>
</LinearLayout>

Related

LinearLayout (vertical) putt 2 Buttons side by side and more buttons below

I have some little problems at creating some buttons. I want to Place 2 Buttons side by side (worked) and more (exp. 3 Buttons) below in a LinearLayout. Actually everything is working for me but if I put another Button the button is below but above there is free space.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<Button
android:id="#+id/button1"
android:text="Button1"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginBottom="200dp" />
<Button
android:id="#+id/button2"
android:text="Button2"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="100dp" />
<Button
android:id="#+id/button3"
android:text="Button3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="200dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Thats how it looks like atm.
first make the width of each button 0dp.
second make the margin bottom equal in the 3 buttons
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<Button
android:id="#+id/button1"
android:text="Button1"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginBottom="200dp" />
<Button
android:id="#+id/button2"
android:text="Button2"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="200dp" />
<Button
android:id="#+id/button3"
android:text="Button3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="200dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:id="#+id/layout_one">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 2"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/layout_one"
android:layout_centerHorizontal="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 3"
/>
</LinearLayout>
</RelativeLayout>
This is the screenshot of pic:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<Button
android:id="#+id/button1"
android:text="Button1"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginBottom="200dp" />
<Button
android:id="#+id/button2"
android:text="Button2"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="200dp" />
<Button
android:id="#+id/button3"
android:text="Button3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="200dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Update your xml with this one, Hope it helps you
here is your code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<Button
android:id="#+id/button1"
android:text="Button1"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginBottom="200dp" />
<Button
android:id="#+id/button2"
android:text="Button2"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="200dp" />
<Button
android:id="#+id/button3"
android:text="Button3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginBottom="200dp" />
</LinearLayout>
</ScrollView>
Just make android:layout_marginBottom="200dp" /> in 2nd button.
This is happening because You have gave the centre gravity to LinearLayout.
The solution is only that you just remove that gravity tag and run again
Replace this
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
to this
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent">
If you want to place the 3 buttons below each other, you should set the orientation of your LinearLayout to vertical instead of horizontal. This will display your buttons in a vertical order.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<Button
android:id="#+id/button1"
android:text="Button1"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton" />
<Button
android:id="#+id/button2"
android:text="Button2"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton" />
<Button
android:id="#+id/button3"
android:text="Button3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton" />
</LinearLayout>
</ScrollView>
</RelativeLayout>

Android LinearLayout: Layout inside a Layout

I am confused by Android layout design. I want to achieve the layout in the following image:
But the code below is producing something like this image:
My code
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_below="#+id/view"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/bg_shadow"
android:animateLayoutChanges="true"
android:layout_marginTop="5dp"
android:id="#+id/detailsLay">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/repeat"
android:id="#+id/repeatCheckBox"
android:longClickable="false"
android:textColor="#android:color/background_light"
android:paddingTop="15sp"
android:paddingRight="15sp"
android:paddingLeft="1sp"
android:paddingBottom="15sp" />
<TextView
android:layout_width="30dp"
android:layout_height="20sp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/sat"
android:id="#+id/satTextView"
android:layout_gravity="center_vertical|right"
android:textColor="#android:color/holo_orange_light"
android:layout_marginLeft="2sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/arrowDown"
android:src="#android:drawable/arrow_down_float"
android:layout_gravity="center_vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/everyday"/>
</LinearLayout>
</LinearLayout>
This is just a Sample Xml learn from this.
<?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="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CheckBox" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
Use attributes like weight and user orientation of linearlayout.

how to set in textview same sizes

I need to implement textview with equal sizes for 3 character, but i have got some problem if i add:
This four buttons have got diferent sizes ...but i dont know why, and how can i change
MOD
_X_
_(_
_5_
_ is white spaces..
There is xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1dp" >
<TextView
android:id="#+id/item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" >
</TextView>
<TextView
android:id="#+id/item_text_Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp" >
</TextView>
End there is picture of my problem:
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="4"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:gravity="center"
android:text="MC_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="MS_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="M+_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_(_"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:layout_marginLeft="5dp"
android:text="_)_"/>
</LinearLayout>
</LinearLayout>
Give your TextView a fix size width by changing layout_width from wrap_content to some fix dp size like 30dp
Example:
<TextView
android:id="#+id/item_text"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:text="MOD"
android:textSize="12sp" >
</TextView>
look like you try to make button in table like in XML???
don`t know if this can help you, but when i try to make same precise width i use this...
here`s the explanation
create 1 linear layout with vertical orientation (so, everytime you add new item, it will placed to down)
inside it, insert linear layout with horizontal orientation... (insert as many row you want, in you case looks like you need 5 linear layout with horizontal orientation)
after that, insert you button / textview inside the linear layout (horizontal orientation), so your button / text will placed horizontaly.
if you want to change row, just insert the button / textview inside another linear layout (horizontal orientation).
after you insert all, set the linear layout (horizontal value) with this code
android:weightSum="5"
why 5? because in your case, u make 5 column.
and dont forget to set the width = fill parent.
after that set the button /textview inside the linearlayout (horizontal) with add this code
android:layout_weight="1"
and dont forget to change the width with fill parent.
with this, i can make precise width in every row. next step you can set the margin to make your button / textview looks good.
hope this can help you...
=====================================
here`s the code if you confuse with my explanation
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tes.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button22"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button21"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button24"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button23"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button20"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button17"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button16"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button19"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button18"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button15"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button14"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button13"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<Button
android:id="#+id/Button07"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button06"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button09"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button08"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button05"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<Button
android:id="#+id/Button04"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
</LinearLayout>

How to align 3 buttons to the bottom of layout?

I have a linear vertical layout in which I have a TextView.
And three buttons in a line.
I want to put those 3 buttons at the bottom of the layout.
I tried bottom layout but it doesn't seem to work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/msgTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<Button
android:id="#+id/previousButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Previous" />
<Button
android:id="#+id/shareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Share" />
<Button
android:id="#+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Next" />
</RelativeLayout>
In this case the buttons come just below the textview and not at the bottom.
Try this>>>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/msgTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/previousButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Previous" />
<Button
android:id="#+id/shareButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Share" />
<Button
android:id="#+id/nextButton"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Next" />
</LinearLayout>
</RelativeLayout>

Not able to align the button and textView in xml

I have a problem in aligning an button and textView. I already have an textView and button in xml and i want another set of those, just below them.
But i am not able to add it. Please have a look at it.
Here is the xml,
<?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:animateLayoutChanges="true"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top">
<com.aavishkaar.quikies.widget.TypedfacedTextViewxmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf" />
<Button style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light" />
<Button style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"/>
</LinearLayout>
</LinearLayout>
Try this code just change orientation in your first linear layout by default linear layout orientation is horizontal
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top">
<com.aavishkaar.quikies.widget.TypedfacedTextView
xmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"
/>
</LinearLayout>
<com.aavishkaar.quikies.widget.TypedfacedTextView
xmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"
/>
</LinearLayout>
</LinearLayout>
Add
android:orientation="vertical" in first Linear Layour.
Add
android:orientation="horizontal" in Second Linear Layour.
I hope this will work , if not ignore this answer .
I'm Not very Good at this.

Categories

Resources