Reputation: 8674
I have a textView in a list item with another text view below it. I am facing one problem again and again that when text increases . text view above overrides my text view below or text view below comes on top of text view above.
My XML in RelativeLayout is :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tp_White"
android:minHeight="60dp">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:layout_marginStart="23dp"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textview1"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textview1"
android:layout_centerVertical="true"
android:layout_marginEnd="23dp"
android:layout_marginRight="23dp"
android:background="@color/tp_White"
android:gravity="center_vertical|center_horizontal"
android:maxLines="2"
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#737574"
android:textSize="15dp" />
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/tp_inactive_channel_text_color"
android:textSize="11dp"
android:layout_below="@+id/textview1"
android:layout_alignLeft="@+id/textview1"
android:layout_alignStart="@+id/textview1" />
i know this is very basic problem but this is very undefined for me and i am not able to position this views such that they dont cut each other. Any help will be appreciated.
Upvotes: 0
Views: 229
Reputation: 419
You should use LinearLayout (just copy and paste it)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="25dp"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#737574"
android:textSize="15dp" />
</LinearLayout>
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="11dp"
/>
</LinearLayout>
Upvotes: 1
Reputation: 126
What are you trying to achieve by writing android:layout_alignTop="@+id/textview1"
and at same time android:layout_alignBottom="@+id/textview1"
.
Instead you can try android:layout_below="@+id/textview1"
this will align your textview
vertically.
Upvotes: 1
Reputation: 13785
You need to use layout_alignParentRight
in your code.
its not proper way you set margin to set view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tp_White"
android:minHeight="60dp">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/textView1"
android:layout_alignParentRight="true"
android:gravity="right"
android:background="@color/tp_White"
android:maxLines="2"
android:text="Loading..."
android:textColor="#737574"
android:textSize="15dp" />
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textSize="11dp"
android:layout_below="@id/textview1"
/>
Upvotes: 1