user2330792
user2330792

Reputation: 67

android textview right of a multiline textview

enter image description herei am suppose to place a TextView right of a multiline TextView.

please check the code below .

<RelativeLayout
    android:id="@+id/rltest"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/rlanswer"
    android:layout_marginLeft="@dimen/grdiviewspacing"
    android:layout_marginRight="@dimen/grdiviewspacing"
    android:background="@android:color/transparent" >

    <TextView
        android:id="@+id/lblanswer2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:ellipsize="end"
        android:lines="1"
        android:text="@string/strbookmarkmessage"
        android:textColor="@color/black"
        android:textSize="@dimen/listviewlocationsize"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/btnyesiwillcollectitby"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:layout_toRightOf="@id/lblanswer2"
        android:autoLink="all"
        android:linksClickable="true"
        android:text="@string/stryesiwillcollectitby"
        android:textColor="@color/linkcolor"
        android:textSize="@dimen/listviewlocationsize" />
</RelativeLayout>

i have tried the problem with the above code is its not showing the second TextView. where us if i try layout_below - its showing the second text view. can anyone please assists me.. i want something like this - blue textview text to read textview.

Upvotes: 0

Views: 235

Answers (2)

Yoann Hercouet
Yoann Hercouet

Reputation: 17986

If you want to keep using a RelativeLayout, you will have to set the width in dip (instead of wrap_content) for the TextView "lblanswer2", otherwise it will always take the whole place if your text is long.

If using a RelativeLayout is not a necessity, you can follow pratik's answer and implement a LinearLayout, this way your 2 TextViews will share the width equally.

Upvotes: 0

Pratik Dasa
Pratik Dasa

Reputation: 7439

Use LinearLayout instead of RelativeLayout and give layout_weight=1 to both the TextView you will get result whatever you want.

Upvotes: 1

Related Questions