让DrawableRight被推到屏幕边缘

时间:2014-07-05 12:36:28

标签: android android-layout

我试图用类似于iOS披露指示器的textitem和drawableRight来显示ListView(实际上是一个DragSortListView)。我无法将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>

@ drawable / navigate是一个显示“&gt;”

的图像

1 个答案:

答案 0 :(得分:0)

看起来DragSortListView导致文本被包装,因为getMeasuredWidth没有按预期获取整个宽度。有github issue突出显示此问题,该票证中显示的solution似乎完美地解决了这个问题。对不起噪音。