ARR.s
ARR.s

Reputation: 769

Textview2 is not showm when TextView1 have more than one line

I have some problem when Textview1 have more than one line.

Example: textview1 have one line, textview2 is shown.

enter image description here

But if textview1 have more than one line, textview2 is not shown because textview1 is full.

enter image description here

And my .xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:padding="5dp"
        android:layout_height="match_parent">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:layout_marginTop="10dp">

            <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:id="@+id/img_vote"
                android:src="@drawable/vote_t_1"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="xxxxxxdfkldjsklfjsdxxxxxx"
                android:id="@+id/tx_poll"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/img_vote"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ttt"
                android:id="@+id/tx_count_vote"
                android:gravity="center"
                android:textColor="@color/color_white"
                android:textSize="@dimen/tx_size_smally"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:background="@drawable/bg_count_poll"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/tx_poll"/>

        </RelativeLayout>
    </RelativeLayout>

</RelativeLayout>

How to fix it?

Upvotes: 0

Views: 128

Answers (5)

Ashray P. Shetty
Ashray P. Shetty

Reputation: 700

In case of having textviews side by side its always recommended to use Linear Layout with weight = 1 for both the textviews.

Try this :

<LinearLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"   
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textViewprimary"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="abcd" />

<TextView
        android:id="@+id/textViewSecondary"
        android:layout_width="0dp"           
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="efgh" />
</LinearLayout>

Upvotes: 3

Neha
Neha

Reputation: 76

Set the property android:layout_toLeftOf="@+id/tx_count_vote" in tx_poll and you can also set maxLength of the textView to prevent overlapping and fixing the area of tx_poll textView

Upvotes: 0

Andrii Lisun
Andrii Lisun

Reputation: 663

That's because you have android:layout_height="wrap_content" on your android:id="@+id/tx_poll". When there is a lot of text it shifts your android:id="@+id/tx_count_vote" and it becomes invisible.

You have this options:

  1. Add fixed size for tx_poll TextView. Something like: android:layout_width="90dp"

  2. Use LinearLayout with layout_weight

  3. Use PercentRelativeLayout

Upvotes: 0

saurabh dixit
saurabh dixit

Reputation: 873

Do it like this

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

<RelativeLayout
    android:layout_width="match_parent"
    android:padding="5dp"
    android:layout_height="match_parent">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_marginTop="10dp"
        >

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:id="@+id/img_vote"
            android:src="@drawable/vote_t_1"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_toRightOf="@+id/img_vote"
            android:weightSum="2">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="xxxxxxdfkldjsklfjsdxxxxxx"
            android:id="@+id/tx_poll"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ttt"
            android:id="@+id/tx_count_vote"
            android:textColor="@color/color_white"
            android:textSize="@dimen/tx_size_smally"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:background="@drawable/bg_count_poll"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"/>

        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

Upvotes: 0

Sourabh Bans
Sourabh Bans

Reputation: 3134

wrap your textviews as tablerow.

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:padding="5dp"
        android:layout_height="match_parent">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:layout_marginTop="10dp">

            <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:id="@+id/img_vote"
                android:src="@drawable/vote_t_1"/>

            <TableRow
            android:weightSum="1"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/img_vote"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_weight=".60" // here manage the weight/percentage
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="xxxxxxdfkldjsklfjsdxxxxxx"
                android:id="@+id/tx_poll"/>

            <TextView
                android:layout_weight=".40"// here manage the weight/percentage
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="ttt"
                android:id="@+id/tx_count_vote"
                android:gravity="center"
                android:textColor="@color/color_white"
                android:textSize="@dimen/tx_size_smally"
                android:background="@drawable/bg_count_poll"
                android:gravity="center"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"/>

            </TableRow> 


        </RelativeLayout>
    </RelativeLayout>

</RelativeLayout>

Upvotes: 0

Related Questions