0

I am trying to use layout_weight in a Linear Layout but it is not setting up proper layout .It's all getting mixed up .proper gap in not there in each textview .Please help me to fix this .

XML

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainResultLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:baselineAligned="false" android:orientation="horizontal" > <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/request_date" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013 | 09:45" android:layout_gravity="left"/> <TextView android:id="@+id/approval_id" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXX" android:layout_gravity="right" /> <TextView android:id="@+id/trip_date" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013" android:layout_gravity="right" /> <TextView android:id="@+id/trip_id" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXXXX" android:layout_gravity="right" /> <TextView android:id="@+id/approval_status" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Waiting" android:layout_gravity="right" /> </LinearLayout> </LinearLayout> 

So please help to fix this issue will be thank full to you..

6 Answers 6

1

try this code to set proper gap in each layout.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainResultLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/request_date" android:layout_width="0dp" android:layout_weight=".20" android:layout_height="wrap_content" android:text="25 Sep 2013 | 09:45" android:layout_gravity="left"/> <TextView android:id="@+id/approval_id" android:layout_width="wrap_content" android:layout_weight=".20" android:layout_height="wrap_content" android:text="XXXXXXXX" /> <TextView android:id="@+id/trip_date" android:layout_width="wrap_content" android:layout_weight=".20" android:layout_height="wrap_content" android:text="25 Sep 2013" /> <TextView android:id="@+id/trip_id" android:layout_width="wrap_content" android:layout_weight=".20" android:layout_height="wrap_content" android:text="XXXXXXXXXX" /> <TextView android:id="@+id/approval_status" android:layout_width="wrap_content" android:layout_weight=".20" android:layout_height="wrap_content" android:text="Waiting" /> </LinearLayout> </LinearLayout> 
Sign up to request clarification or add additional context in comments.

Comments

0
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainResultLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:gravity="center" android:orientation="vertical" > <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/request_date" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center|left" android:layout_weight="1" android:singleLine="true" android:text="25 Sep 2013 | 09:45" /> <TextView android:id="@+id/approval_id" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center|left" android:layout_weight="1" android:singleLine="true" android:text="XXXXXXXX" /> <TextView android:id="@+id/trip_date" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center|left" android:layout_weight="1" android:singleLine="true" android:text="25 Sep 2013" /> <TextView android:id="@+id/trip_id" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center|left" android:layout_weight="1" android:text="XXXXXXXXXX" /> <TextView android:id="@+id/approval_status" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center|left" android:layout_weight="1" android:text="Waiting" /> </LinearLayout> 

Comments

0

Try with android:layout_width="match_perent" in each textview properties

Comments

0

Change *android:layout_width="0dp"* with *android:layout_height="wrap_content"* or *android:layout_height="wrap_content"*.

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/request_date" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013 | 09:45" android:layout_gravity="left"/> <TextView android:id="@+id/approval_id" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXX" android:layout_gravity="right" /> <TextView android:id="@+id/trip_date" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013" android:layout_gravity="right" /> <TextView android:id="@+id/trip_id" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXXXX" android:layout_gravity="right" /> <TextView android:id="@+id/approval_status" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="Waiting" android:layout_gravity="right" /> 

Also, if you don't have to add anything else, you can use only one LinearLayout.

Comments

0

What is the second linear layout doing in the xml?.you want to have all these text views aligned in a line with equal weight?remove the android:layout_gravity="left" from all your text views. Do it like this...

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainResultLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:baselineAligned="false" android:orientation="horizontal" > <TextView android:id="@+id/request_date" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013 | 09:45" /> <TextView android:id="@+id/approval_id" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXX" /> <TextView android:id="@+id/trip_date" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013" /> <TextView android:id="@+id/trip_id" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXXXX" /> <TextView android:id="@+id/approval_status" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Waiting" /> </LinearLayout> 

Comments

0

Just change the width to match_parent in each case.

<LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/request_date" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013 | 09:45" android:layout_gravity="left"/> <TextView android:id="@+id/approval_id" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXX" android:layout_gravity="right" /> <TextView android:id="@+id/trip_date" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="25 Sep 2013" android:layout_gravity="right" /> <TextView android:id="@+id/trip_id" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="XXXXXXXXXX" android:layout_gravity="right" /> <TextView android:id="@+id/approval_status" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="Waiting" android:layout_gravity="right" /> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.