gpt4 book ai didi

android - 避开间隙并放置图像

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

我有一个父线性布局和三个子布局,每个子布局的权重为 3我想从服务器获取图像并将这些图像放置在子布局中并且它工作正常。

但是在放置图像时,每次迭代后我都会获得空间。我的意思是我将迭代图像计数并根据提醒放置这些图像。

图像看起来像这样(三个垂直布局的图像)

|    |    |
| |
|
|
| | |

您可以看到每张图片之间的空白。在第一次迭代中,我得到 5 张图片(比如说),在第二次迭代中,我想将图片放在每个独立布局图片的下方。

我的意思是这样的

 |   |   |
| | |
| | |
| | |

那么如何避免空隙填充图片呢??

这是我的代码

private View setupView(View parentView) {
int itemCount = 1;
LinearLayout columnOdd = (LinearLayout) parentView.findViewById(R.id.column_odd);
LinearLayout columnEven = (LinearLayout) parentView.findViewById(R.id.column_even);
LinearLayout columnCenter = (LinearLayout) parentView.findViewById(R.id.column_center);

View itemView = inflater.inflate(R.layout.custom_view, null);

if (itemCount % 3 == 0) {
columnEven.addView(itemView);
} else if (itemCount % 2 == 0){
columnOdd.addView(itemView);
}
else if (itemCount % 1 == 0) {
columnCenter.addView(itemView);
}
itemCount++;
}

return parentView;

这就是我在布局中膨胀 View 的方式:

View v =  inflater.inflate(R.layout.items, null);                   
v = setupView(v);

if (v != null) {
mCurrentItem++;
mViews.parentLinearLayout.addView(v);
}

最佳答案

如果有大量图像,那么您应该使用 gridview 否则您可能会遇到内存不足的异常。使用 numColumns 为 3 的 gridView。

关于android - 避开间隙并放置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31238152/

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