2014-07-05 161 views
0

我試圖顯示一個帶有textitem和drawableRight的ListView(實際上是一個DragSortListView),類似於iOS披露指示器。我無法將drawableRight放置到屏幕的邊緣,它總是顯示在文本的末尾,而不是在屏幕的邊緣。將DrawableRight推到屏幕邊緣

例如,這是我想要的。

+ Text1 here    > 
+ Text2     > 

但它顯示爲

+ Text1 here> 
+ Text2> 

我已經嘗試了許多佈局選項和建議(因爲我的LinearLayout是水平的),但他們都不來幫忙。我能做到的唯一方法就是將TextView的layout_width設置爲某​​種硬編碼值,例如128dp,這樣它就會出現在屏幕的末尾,但這可能不是一個合適的解決方案,因爲屏幕尺寸可以變化。

你可以看看我的佈局代碼,看看我可能會錯過什麼。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/titleslist_selector_tablet" 
    android:orientation="horizontal" 
    tools:ignore="HardcodedText,UselessParent"> 

    <ImageView 
     android:id="@+id/dragHandle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:background="@android:color/transparent" 
     android:src="@drawable/dragicon" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginBottom="10dp" 
     android:clickable="false" 
     android:layout_weight="0" /> 

    <TextView 
     android:id="@+id/listText" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:drawableRight="@drawable/navigate" 
     android:gravity="left|center" 
     android:paddingBottom="1dp" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#454545" 
     android:layout_weight="1"/> 

</LinearLayout> 

的@可繪製/導航是顯示圖像的「>」

+0

你嘗試從你的'ImageView'和'TextView'中刪除你的'android:weight'屬性嗎? –

+0

@ G.T。是的,我做了,沒有運氣。 – rajasaur

回答

0

它看起來像DragSortListView被導致文本由於getMeasuredWidth不採取全寬爲預期纏繞。有一個github issue強調這個問題,並在該票提出的solution似乎解決這個完美。對不起,噪音。