gpt4 book ai didi

android - 滚动条不会出现在具有多个图像的线性布局中

转载 作者:行者123 更新时间:2023-11-29 15:38:15 24 4
gpt4 key购买 nike

我正在通过如下代码将图像添加到布局中:

linear = (LinearLayout)findViewById(R.id.linearLayout);

for(int i=0;i<15;i++)
{
image = new ImageView(this);
image.setImageResource(R.drawable.img);
linear.addView(i);
}

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">

</LinearLayout>

我的问题是,当我添加超过 3 张图片时,滚动条没有显示。

最佳答案

不是将 LinearLayout 添加为父布局,而是在 ScrollView 中添加线性布局并将子布局添加到 LinearLayout

注意:

ScrollView should have only one immediate child

关于android - 滚动条不会出现在具有多个图像的线性布局中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45802724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com