【发布时间】:2017-09-22 08:18:55
【问题描述】:
我弹出了一个带有标题和关闭按钮的对话框。这是 XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/text_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="24dp"
android:layout_marginRight="0dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:maxLines="1"
<!--- android:singleLine="true" <-- Do not comment about this, it is deprecated --->
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textSize="20sp"
android:textColor="@android:color/black"
/>
<ImageView
android:id="@+id/backburger"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_close"
android:foreground="?android:attr/selectableItemBackground"
/>
</LinearLayout>
就像您可以看到 TextView 具有选取框所需的所有东西一样,singleLine 选项已被弃用,因此我无法使用它。我确实在我的 Java 中调用了setSelected(true)。有很多关于选取框的问题,但对于 layout_weight 和 17 年的问题都没有。
这是 XML 的预览:
【问题讨论】:
-
在这里查看我的答案stackoverflow.com/a/46360549/5381331。我已经用 layout_weight 对其进行了测试,所以这个问题与
android:layout_weight无关。另见stackoverflow.com/a/12005799/5381331