将多个视图插入到一个布局中,而不会溢出到屏幕的末尾

Inserting many views into one layout without them overflowing to the end of the screen

我正在寻找一种可以将视图动态添加到布局(目前是 LinearLayout)并且它们不会溢出到屏幕末端并被隐藏的方法。

我不能使用 ScrollViews,因为它必须看起来像一个句子(这是一个 "fill the blanks" 问题)。

我只是在寻找有关如何执行此操作的想法,而不是代码本身。

提前致谢,谢伊。

如果您使用的是线性布局而不是使用带权重的线性布局:

例如: 您有一个垂直方向的 LinearLayout,其中有 2 个 ImageView,您希望这些 ImageView 始终取相等 space.

<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"/>

这将适用于任何设备,不会溢出到屏幕末端并被隐藏