【问题标题】:Getting DrawableRight to be pushed to edge of the screen让 DrawableRight 被推到屏幕边缘
【发布时间】:2014-07-07 12:28:02
【问题描述】:

我试图显示一个 ListView(实际上是一个 DragSortListView),它带有一个类似于 iOS 披露指示器的 textitem 和一个 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>

@drawable/navigate 是显示“>”的图像

【问题讨论】:

  • 您是否尝试从您的ImageViewTextView 中删除您的android:weight 属性?
  • @G.T.是的,我做到了,但运气不好。

标签: android android-layout


【解决方案1】:

看起来DragSortListView 导致文本被换行,因为 getMeasuredWidth 未按预期获取全宽。有一个github issue 突出显示了这个问题,而该票中的solution 似乎完美地解决了这个问题。对不起,噪音。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2017-10-28
    • 2012-06-07
    • 2014-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多