我正在开发一个应用程序,它将从 SD 卡中获取图像并将它们分别显示在这样的布局中
The Issue is:
假设用户在 SD 卡中有 100 多个文件,要在布局中显示它们,我需要先添加 100 多个 View ,然后再进行样式设置。 错误的方法
My Question is:
可以通过编程方式或通过 XML 完成什么,以便我只能定义五个基本 View ,并根据 SD 卡中的图像数量创建剩余的布局和 View ,以便我可以通过水平滚动访问它们查看。
My research includes:
我尝试使用 GridView 布局,但它不能完全满足我的需求,因为它对所有网格具有统一的大小。此外,我知道如何以编程方式添加布局,但我不知道如何让它与我的设计一起工作。
最佳答案
您可以通过更改 xml 两侧可滚动来实现-
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320px" android:layout_height="fill_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linlay" android:layout_width="320px"
android:layout_height="fill_parent" android:stretchColumns="1"
android:background="#000000"/>
</HorizontalScrollView>
关于android - 以编程方式添加布局android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21429114/