android - 两个使用 XML 的具有动态宽度的第一个 TextView 的水平 TextView
问题描述
我想在 2 个 TextView 的位置构建布局。
第一个 TextView 的长度未定义(?)。所以它必须是单线和椭圆形结束。
第二个 TextView 已定义宽度 (wrap_content)。
我需要第二个 textview 附加到第一个 textview 的末尾,但是如果第一个 textview 的内容长度太大,它应该被省略。
此外,第二个 textview 必须留在父容器的末尾。
我知道这有点令人困惑。看看下面的图片。
可以不用 java/kotlin 编码,只用简单的 xml 来完成吗?
解决方案
这是一个解决方案LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:layout_weight="1"
tools:text="Long" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Short" />
</LinearLayout>
推荐阅读
- flutter - Flutter:在无状态小部件中动画行内容
- python - django loaddata 上的错误(1062,“密钥 'user_id' 的重复条目 '4'”)
- python - 仅替换一个字符的一个实例,而不是每次出现
- python - 为什么有些颜色透明后不能恢复原色
- spring - Spring - 如何在类中注释属性
- python - 为什么 TensorFlow 分类示例不使用激活函数?
- reactjs - 您已多次调用 Google Maps API
- ruby-on-rails - 带有动态参数的 rails 4 中不允许的参数
- python - 我无法在 atom 文本编辑器中安装 autocomplete-python 包
- javascript - 在我的班级中实现添加和删除功能