android - set EditText width in LinearLayout depend on TextView width -


i have following snippet of code. 1 edittext , textview in horizontal linearlayout. want set edittext width depend on textview width. if width of textview means text increase need adjust editext width

<?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:id="@+id/titlelinearlayout"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:background="#224386"         android:orientation="horizontal"         android:padding="5dp" >          <edittext             android:id="@+id/titleedittext"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_weight="0.1"             android:background="@drawable/gradient_edittext"             android:ellipsize="end"             android:gravity="right|center_vertical"             android:singleline="true" />          <textview             android:id="@+id/titletextview"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_weight="0.1"             android:gravity="right"             android:text="name"             android:textcolor="#ffffff"             android:textsize="16dp" />     </linearlayout>  </linearlayout> 

thank in advance.enter image description here

if you, use relativelayout instead of linearlayout.

<?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" >      <relativelayout         android:id="@+id/titlelinearlayout"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:background="#224386"         android:padding="5dp" >          <textview             android:id="@+id/titletextview"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentright="true"             android:gravity="right"             android:text="name"             android:textcolor="#ffffff"             android:textsize="16dp" />          <edittext             android:id="@+id/titleedittext"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_toleftof="@id/titletextview"             android:background="@drawable/gradient_edittext"             android:ellipsize="end"             android:gravity="right|center_vertical"             android:singleline="true" />     </relativelayout>  </linearlayout> 

it produce output want.

also notice setting gravity textview useless wraps content. same applies center_vertical value edittext's gravity because wraps content height-wise.


Comments