Reputation: 1675
I have a LinearLayout, horizontal, and with variable width (width is set to fill parent) containing two textboxs A and B.
I need : textbox B (the black one) takes as much width as it needs (wrap_content ?) textbox A takes what's left.
Pictures to illustrate :
Upvotes: 1
Views: 147
Reputation: 737
Try the following code:
<?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="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.35"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asd" />
</LinearLayout>
Upvotes: 4
Reputation: 2731
use relativelayout instead.like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- black box -->
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"/>
<!-- white box -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/txt1"
android:singleLine="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
NOTE: i see in some device,because of language direction or device setting, linearlayout change children position. for example black text box come to left and white text box goes to right,but if use relativlayout it never happen.
Upvotes: 0