質問

I am new to Android, i have below task.

I want to align three TextViews adjacent to each other with ellipsis if the text is too long . Currently i am using below code which aligns my TextView adjacent to each other, but my problem is if the text is too long, the below code not putting the ellipsis. i got some trick to use both toleftof and torightof from here, but in my case it going to circular dependency as mentioned here.

<RelativeLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_toRightOf="@+id/reminderText">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/noteTagOne"
                    android:ellipsize="end"
                    android:singleLine="true"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/noteTagTwo"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:layout_toRightOf="@+id/noteTagOne"
                    android:layout_marginLeft="5sp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/noteTagThree"
                    android:layout_toRightOf="@+id/noteTagTwo"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:layout_marginLeft="5sp"/>
     </RelativeLayout>

I want output as,

Tag1... Tag2... Tag3...  

Basically, i want some ideas, whether in xml i can achieve this or need to do it programmatically, since TextView text's are dynamic i cannot fix maxLength, sometimes only single tag may exist, at that time it should take full text.

Note: I am developing Android project using C# in Xamarin.

enter image description here

Added code is for the above highlighted part. I fixed overlapping of tagsicon & text. Now only two issues.

1) Last tag is overlapping with right aligned image. 2) If TextView texts are short, gap is shown in-between the tags

How to fix it?

役に立ちましたか?

解決

try this solution

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/noteTagOne"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:maxWidth="100dp"
    android:singleLine="true"
    android:text="Tag111111111111111111"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/noteTagTwo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5sp"
    android:layout_toRightOf="@+id/noteTagOne"
    android:ellipsize="end"
    android:maxWidth="100dp"
    android:singleLine="true"
    android:text="Tag2222222222222222"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/noteTagThree"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5sp"
    android:layout_toRightOf="@+id/noteTagTwo"
    android:ellipsize="end"
    android:maxWidth="100dp"
    android:singleLine="true"
    android:text="Tag3333333333333333"
    android:textAppearance="?android:attr/textAppearanceLarge" />

他のヒント

Use this android:ellipsize="marquee" it will work

android:ellipsize="marquee" 

or

android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top