0

My layout code as below:

 <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:gravity="center_vertical" android:orientation="horizontal" > <Button android:id="@+id/btn_left" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="Phone Files" /> <TextView android:id="@+id/list_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:gravity="center_horizontal" android:text="Photos" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/btn_right" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="Save" /> </LinearLayout> 

How to let the btn_left and btn_right have the same size?

1
  • If there is no any more importance then why you not give the same size to that both button ? I mean android:width="50dp" like that. Commented Jan 6, 2012 at 4:20

2 Answers 2

1

If there is no any more importance of weight then just remove the weight from your layout and give equal size to that both Button. See Below:

Edited:

Create the String in to your string.xml file as like:

 <string name="button_name">Phone "\n" Files</string> 

then Put the Below code and it will show you the Button with two line text.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:gravity="center_vertical" android:orientation="horizontal" > <Button android:id="@+id/btn_left" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/button_name"/> <TextView android:id="@+id/list_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:gravity="center_horizontal" android:text="Photos" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/btn_right" android:layout_width="100dp" android:layout_height="wrap_content" android:text="Save" /> </LinearLayout> 

Hope it works as you want. Thanks. Enjoy.

Sign up to request clarification or add additional context in comments.

4 Comments

i m wondering does linearlayout usesS android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
But I want the left button text show 2 rows, and the right one only 1 row.
Ok I have solved your problem. Please wait for my edited Answer.
@brian : If you got the solution then you can accept the answer so that can help others. and also give upvote with all sutable answers.
1

Try adding android:weightSum="2.5" as an attribute to your LinearLayout tag and change the layout_width values of all three widgets to android:layout_width="0dip"

4 Comments

Edited, completely overlooked the fact that you had weights set to fill_parent, try changing those to 0dip
"0dip" in attribute "layout_weight" cannot be converted to float
Wow.. layout_width, not layout_weight, my apologies.. trying to do too many things at once
It make the button become very width, but I did not want it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.