【发布时间】:2017-01-29 22:48:02
【问题描述】:
我有一个包含 TextView 和 ImageView 的 LinearLayout。 TextView 的宽度设置为wrap_content,但问题是当宽度达到父宽度时。文本内容将正确换行至 2 行或更多行,但 TextView 和 ImageView 将在左侧和右侧被剪裁。我能找到的最相似的问题是this one,它是 2013 年的,没有解决方案。
具体来说,我在this view 遇到了这个问题,但我创建了以下更简单的视图来举例说明这个问题:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_top_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/card_top_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One Two Three Four Five"
android:textSize="40sp"/>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_volume_up_black_48dp"/>
</LinearLayout>
当布局与另一个视图重叠时,在 LinearLayout 上设置 android:clipChildren="false" 甚至不会阻止剪辑。
这是最终图像,以证明它发生在真实设备上,而不仅仅是布局查看器:
我基本上没有想法。有什么想法吗?这是Android布局系统的问题吗?感谢您的帮助和考虑!
【问题讨论】:
标签: android android-layout textview android-linearlayout