[英]Prevent the keyboard from overflowing my LinearLayout after it shows up?
[英]Why my items are overflowing out of my LinearLayout?
我有这个 包含以编程方式添加的八个项目。
但是正如大家所看到的,这些项目从屏幕溢出到右侧。
有我的LinearLayout代码:
<LinearLayout
android:id="@+id/items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/segmento"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="16dp">
通过{ImageView}.setLayoutParams(new LinearLayout.LayoutParams(184, 184));
以编程方式添加LinearLayout内部的{ImageView}.setLayoutParams(new LinearLayout.LayoutParams(184, 184));
然后是items.addView({ImageView})
仅添加信息, "@+id/segmento"
在屏幕截图中是不可见的。
谢谢! :D
线性布局不支持溢出到下一行。
您只能在子项上划分可用空间,以便每个子项都足够小,以使所有子项彼此相邻。 (为此,请查看布局参数上的weight
属性)。
但是,您真正想要的是称为FlexBoxLayout 。 Google不久前已将其移植到Android,并且可以完全满足您的要求。
尝试将布局宽度设置为match_parent。 由于您的方向设置为水平,宽度设置为wrap_content,因此可能没有考虑屏幕尺寸。
以编程方式添加图像视图时,尝试将MATCH_PARENT用于宽度和WRAP_CONTENT:
{ImageView}.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
,LinearLayout.LayoutParams.WRAP_CONTENT));
items.addView({ImageView})
这样可以确保它也可以在具有不同屏幕尺寸的设备上使用。 如果您对宽度和高度进行硬编码,则可能无法在所有设备上使用。
同样在您的布局中,将线性布局更改为
android:layout_width="match_parent"
android:layout_height="wrap_content"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.