android - How to make the ellipsize textview and imageview show correct -


i'm working on layout file. layout requires icons should after single line textview. if textview long,then textview ellipsize , icons should shown.such as:

situation1: [[textview][icon1][icon2]      ]

situation2: [[textview......][icon1][icon2]].

i have found similar case in here, doesn't work me.

my current code this:

 <relativelayout             android:id="@+id/parent"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center_vertical"             android:gravity="left">               <!-- icon show here -->             <linearlayout                 android:id="@+id/icons"                 android:paddingleft="5dp"                 android:orientation="horizontal"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="center_vertical"                 android:layout_alignparentright="true"                 android:layout_centervertical="true"                 android:gravity="center_vertical|left">              </linearlayout>               <!--text show here-->             <textview                 android:id="@+id/text"                 android:layout_height="wrap_content"                 android:layout_width="wrap_content"                 android:layout_toleftof="@id/icons"                 android:singleline="true"                 android:ellipsize="end"                 android:gravity="left"/>            </relativelayout> 

the linearlayout used add icons when fetch data server. android's layout preview above situation,but apk runs on device this:

situation1: [      [textview][icon1][icon2]]

situation2: [[textview......][icon1][icon2]].

i'm confused. has ideas situation? in advance.

i found code works fine after android 4.3(include 4.3,i haven't test 4.2),it doesn't work below android 4.3.the reason think different android systems parse these layout params in different ways.such version think parent container layout's params more important child view.

finally, got stupid situation.but works.i give code:

<linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">              <linearlayout                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:orientation="horizontal">                  <!--text show here-->                 <textview                     android:id="@+id/text"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:ellipsize="end"                     android:singleline="true"                     android:layout_weight="1" />                   <!-- icons show here -->                 <linearlayout                     android:id="@+id/icons"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_centervertical="true"                     android:layout_gravity="center_vertical"                     android:orientation="horizontal">                  </linearlayout>              </linearlayout>              <textview                 android:layout_width="0dp"                 android:layout_weight="1"                 android:layout_height="wrap_content"                 android:layout_gravity="right"/>          </linearlayout> 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -