【发布时间】:2020-09-15 20:01:55
【问题描述】:
所以我有这样的事情:
LinearLayout:
LinearLayout - wrap_content, background black:
TextView - wrap_content
LinearLayout:
Image - 20dp
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="center|start"
android:padding="5dp"
android:layout_margin="2dp">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="klgjdkljgilfdjgidfhjiogjdio;jhgiju;fgjdhjgu;hdfuighdfuk;ghduk;fhgukldhfgujkdfhyufhglfdhguldfhguklhfdulghldfughyulfhdulghdfulghul"
android:textColor="#D5D5D5" />
<LinearLayout
android:layout_width="15dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginBottom="2dp"
android:layout_height="match_parent">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="bottom|center"
android:src="@drawable/edit" />
</LinearLayout>
</LinearLayout>
这很好用,但是当 TextView 包含大于屏幕大小的文本时,图像会超出屏幕。我不希望这种情况发生。
示例如下:
谢谢!
【问题讨论】:
-
如果你也上传你的 XML 更好理解
-
我的 XML 文件太长,但可以添加。
-
您只是为您提到的视图添加
-
修复文本视图的宽度添加自定义宽度或使用约束布局
-
我希望 TextView 的宽度是动态的,但也不要在最后截断图像。
标签: android xml android-studio layout