android - 以编程方式添加布局android

标签 android xml android-layout

我正在开发一个应用程序,它将从 SD 卡中获取图像并将它们分别显示在这样的布局中

enter image description here

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/

相关文章:

javascript - 如何在 Javascript 中硬编码一个大的 XML 字符串?

php - 从 XML 站点地图中获取所有链接,并将它们放入一个数组中?

android - 如何展开和折叠以 EditText 作为其子项的 textView

android - 高程不适用于 LinearLayout

android - SQLite 查询未按特定顺序执行

android - JSON 数据解析 - 如何?

android - 使用react-navigation在屏幕之间导航

java - 运行 5 分钟后,我的 libgdx 游戏崩溃并变黑

xml - xpath:测试节点是否是除指定ok元素之外的唯一子节点

android - 如何使用 Android Studio 的 Tablayout Activity 在没有 fragment 的情况下更改布局?