Android button width half of available width - Layouts - java

I have made a layout with imageview and some buttons i want the buttons to have half the available screen width and height.
This is what I have tried, my xml is as follows.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/imageidid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/actionbar_bg" />
</LinearLayout>
<LinearLayout
android:id="#+id/1st row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/imageid"
>
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="row1 col1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="row1 col2" />
</LinearLayout>
<LinearLayout
android:id="#+id/2nd row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/1st row"
>
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="row2 col1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="row2 col2" />
</LinearLayout>
</RelativeLayout>
and the output looks like this.
and I want something like this.(note imageview to take 40% of screen height)

here is the code you need to achive what you want, you can just change the wight of the views to set the percentage of screen you want the view to take:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:scaleType="centerCrop"
android:src="#drawable/actionbar_bg" />
<LinearLayout
android:id="#+id/1st row"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#id/imageid"
android:layout_weight="30"
android:orientation="horizontal" >
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="row1 col1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="row1 col2" />
</LinearLayout>
<LinearLayout
android:id="#+id/2nd row"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#id/1st row"
android:layout_weight="30"
android:orientation="horizontal" >
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="row2 col1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="row2 col2" />
</LinearLayout>
</LinearLayout>

Try this, notes:
according to the "hint" nested weights are bad for performance, nevertheless look at the code,
Fill_parent is deprecated, use match_parent
Your "image" is not representative of the percentages visually, in any case, it is easy to change,
Code:
<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:id="#+id/imageid"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:contentDescription="#string/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/actionbar_bg" />
</LinearLayout>
<LinearLayout
android:id="#+id/1strow"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="horizontal" >
<Button
android:id="#+id/btn11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/row1col1" />
<Button
android:id="#+id/btn21"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/row1col2" />
</LinearLayout>
<LinearLayout
android:id="#+id/2ndrow"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="horizontal" >
<Button
android:id="#+id/btn12"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/row2col1" />
<Button
android:id="#+id/btn22"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/row2col2" />
</LinearLayout>
</LinearLayout>

Your RelativeLayout isn't doing anything special, so change it to a LinearLayout (leave both width and height attributes as "match_parent" but add
android:orientation="vertical"
Then for each of your smaller LinearLayouts, add:
android:layout_weight=".xx"
where xx is the percentage of the large LinearLayout that you want your child layouts to use.
Background reference here, please do make sure to read it:
http://developer.android.com/guide/topics/ui/layout/linear.html

You can use LinearLayout as a main layout and then use weightsum property of linear layout

Related

How do you set a scrollView to fill the remainder of the screen with a static navbar at the bottom?

My goal is to have 2 static buttons at the bottom of the screen at all times "Back" and "Add Event." I have a scrollView that holds a list of items, currently that view just shows one row instead of all that rows that can fit on the screen. The reason I used a scrollView was because I wanted the user to be able to scroll through more options if it exceeds the screen length. Is there a way to expand the Scrollview/Listview without using DP(since that doesn't always correlate well with different screen sizes).
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<ListView
android:id="#+id/user_event_table"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|bottom"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/back_button"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="back" />
<Button
android:id="#+id/add_button"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:text="add Event" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Do not nest ListView inside ScrollView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<Button
android:id="#+id/back_button"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:text="back"/>
<Button
android:id="#+id/add_button"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:text="add Event"/>
</LinearLayout>
<ListView
android:id="#+id/user_event_table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/button_layout"
android:layout_alignParentTop="true"/>
</RelativeLayout>
Here is the solution
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/user_event_table"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|bottom"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/back_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="back" />
<Button
android:id="#+id/add_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:text="add Event" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Center button in a LinearLayout

I just want to center "CenterButton" (center of the root LinearLayout) but Androids just not cooperating..
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.00"
android:padding="5dp"
android:background="#zegerg"
android:id="#+id/LinearLayout1">
<ImageView
android:id="#+id/ImageView1"
android:layout_height="match_parent"
android:layout_width="151dp"
android:src="#mipmap/image_1"
android:contentDescription="#string/abcdef"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:id="#+id/CenterButton"
android:layout_gravity="center_horizontal|center_vertical|center"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text !"
android:id="#+id/TextView"
android:paddingBottom="30dp"
android:textColor="#37a52c" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ProgressBar"
android:paddingBottom="30dp"
android:progressTint="#37a52c" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_text"
android:id="#+id/Button2"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
Tried putting it at the end of the XML but doesn't work because the other elements push it aside.. not really sure what's happening.
if you want to have all three first level children to be in equally-sized columns, then you need to add to all of them the followings attribute:
android:layout_width="0dp"
android:layout_weight="1"
(don't forget the dimension "dp" to the width parameter, otherwise the IDE will complain).
...
<ImageView
android:id="#+id/ImageView1"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:src="#mipmap/image_1"
android:contentDescription="#string/abcdef"/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button"
android:id="#+id/CenterButton"
android:layout_gravity="center_horizontal|center_vertical|center"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:padding="20dp">
....
EDITED:
If you want your CenterButton to overlap all the other views, then what you have to do is:
wrap everything in a relative layout with height equal to 200dp, as its first child
remove the button CenterButton from the current position and add it at the bottom of everything, still inside the relative layout, but below the linear layout
add those properties to the button to make it center in the parent
android:layout_centerInParent="true"
So finally you will have something like this (I have changed some resources):
<?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="200dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.00"
android:padding="5dp"
android:background="#android:color/holo_orange_dark"
android:id="#+id/LinearLayout1">
<ImageView
android:id="#+id/ImageView1"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:src="#drawable/plus"
android:contentDescription="abcdef"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text !"
android:id="#+id/TextView"
android:paddingBottom="30dp"
android:textColor="#37a52c" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ProgressBar"
android:paddingBottom="30dp"
android:progressTint="#37a52c" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"
android:id="#+id/Button2"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Button"
android:id="#+id/CenterButton"
android:layout_gravity="center_horizontal|center_vertical|center"/>
</RelativeLayout>
You can use weight for such purposes for child items. Make layout_width for all of them as 0dp and set layout_weight as 1.
Give the three children in the topmost linear layout a gravity of 1 and a width of 0.
It's not clear what exactly is your problem. However, here are some general notes :
To center a View or a Layout inside RelativeView use layout_centerInParent="true"
To make a Layout on top of other layouts use FrameLayout
The order of the views/layouts in your xml file is important. The one you write the last will be on the top (in our example : the FrameLayout or just the CenterButton should be written after the other views and layouts in your xml file)
To distribute the available space inside LinearLayout among its views use android:layout_weight="1" (change the value according to your needs)
you can play aground with this example :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="200dp">
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#fff"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/ImageView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:src="#mipmap/ic_launcher" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="#+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:text="Text !"
android:textColor="#37a52c" />
<ProgressBar
android:id="#+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:progressTint="#37a52c" />
<Button
android:id="#+id/Button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text_text" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<Button
android:id="#+id/CenterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical|center"
android:text="Button" />
</FrameLayout>
</RelativeLayout>

creating a new linear layout

i created button and other...
but now when i want to create a three buttons green,red,blue they are not showing up i want them to be directly down the button1 but they are not showing up i wish you can help me this is the error im getting -xml documents must start and end within the same entity the error is showing in the last last last linearlayout
this is the code im having problem with
<?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/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Greetings"
android:textSize="20sp" />
<Button
android:id="#+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:id="#+id/fourthLine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:id="#+id/fifthLine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</RelativeLayout>
</LinearLayout>
this is a picture for the red blue green buttons where to be while mine are down
https://www.dropbox.com/s/73grdc0iff3ql3u/Untitled.png
this is what i reached to till now but i want them to be equally distributed like the picture above
https://www.dropbox.com/s/73grdc0iff3ql3u/Untitled.png
you have not closed the below linear layout tag in your xml.
"<"LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal" ">"
You need one more </LinearLayout> at the end of your xml file. At the minute, only 2 of the 3 LinearLayout's are being closed.
EDIT
The reason your Buttons are appearing at the bottom is because of this:
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</RelativeLayout>
I'm not sure what purpose this serves in your application, but removing that will fix your problem.
Replace your xml with following code
<?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/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
<Button
android:id="#+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="HelloWord" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:weightSum="10" >
<TextView
android:id="#+id/thirdLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3.3"
android:background="#ff0000"
android:text="red"
android:textColor="#000000"
android:gravity="center" />
<TextView
android:id="#+id/fourthLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3.4"
android:background="#00ff00"
android:text="green"
android:textColor="#000000"
android:gravity="center" />
<TextView
android:id="#+id/fifthLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3.3"
android:background="#0000ff"
android:text="blue"
android:textColor="#000000"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
Hope it will help you.

My items in my listView are not aligning properly?

rather than explain what's happening, here's a screen-grab:
As you can see my item list is aaaalll over the shop. Going to paste both activity_main.xml and another one that formats the list, list_row.xml
ACTIVITY_MAIN.XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#121212">
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/main_title"
android:textColor="#33b5e5"
android:background="#1f1f1f"
android:textStyle="bold"
android:textSize="14sp"/>
<ListView
android:id="#+id/android:list"
android:background="#121212"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="2dip"/>
</LinearLayout>
LIST_ROW.XML
<?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="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:background="#121212">
<TableLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:background="#121212">
<TableRow>
<ImageView
android:id="#+id/icon"
android:padding="2dip"
android:background="#121212"/>
<TextView
android:id="#+id/description"
android:padding="2dip"
android:textSize="18sp"
android:textColor="#ffffff"
android:singleLine="true"
android:background="#121212"/>
</TableRow>
</TableLayout>
</LinearLayout>
Try giving weights to ImageView and TextView like android:layout_weight as the ratio you want.
And dont forget to make android:layout_width = "match_parent" otherwise weights will have no effect..
remove the Table layout
and use this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:background="#121212"
android:orientation="horizontal"
android:padding="6dip" >
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#121212"
android:padding="2dip"
android:src="#drawable/instructions" />
<TextView
android:id="#+id/description"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#121212"
android:padding="2dip"
android:singleLine="true"
android:text="tomer"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>

Android: How to make the margin of a button relative to screen width?

for example I want the button's margin to be 1/4 of the screen width (in pixels), what should I do? I prefer to change something in layout xml file instead of coding.
<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:weightSum="4" >
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
Use weightSum and layout_weight to achieve this.
For e.g
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
android:visibility="visible" >
<Button
android:id="#+id/sign_in_button"
android:layout_weight="25"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="testing" />
</LinearLayout>

Categories

Resources