我正在寻找一种可以将 View 动态添加到布局(目前是 LinearLayout)并且它们不会溢出到屏幕末端并被隐藏的方法。
我不能使用 ScrollViews,因为它必须看起来像一个句子(这是一个“填空”问题)。
我只是在寻找有关如何执行此操作的想法,而不是代码本身。
提前致谢,谢伊。
最佳答案
如果您使用线性布局而不是使用带权重的线性布局:
例如: 你有一个垂直方向的 LinearLayout,里面有 2 个 ImageView,你希望这些 ImageView 总是占据相等的空间。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="2"
android:orientation="vertical"
android:layout_gravity="center">
可以将每个ImageView的layout_weight设置为1,LinearLayout中的weightSum设置为2来实现。
<ImageView
android:layout_height="wrap_content"<br/>
android:layout_weight="1"
android:layout_height="0dp"/>
这将适用于任何设备而不会溢出到屏幕末端并被隐藏
关于android - 将多个 View 插入到一个布局中,而不会溢出到屏幕的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34728841/