• Android 通用首页代码示例


    Android 中,使用 NestedScrollView 来包含多个部分,如横向 Banner、GridView 和 RecyclerView,可以通过嵌套不同的布局组件来实现。以下是一个示例布局的 XML 文件,展示如何将这些部分嵌套在 NestedScrollView 内:

    
    <androidx.core.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context=".MainActivity">
    
        
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/bannerRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" />
    
            
            <GridView
                android:id="@+id/gridView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:numColumns="2"
                android:columnWidth="160dp"
                android:stretchMode="columnWidth"
                android:gravity="center"
                android:verticalSpacing="8dp"
                android:horizontalSpacing="8dp" />
    
            
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            
            
    
        LinearLayout>
    androidx.core.widget.NestedScrollView>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46

    在这个示例布局中:

    1. 使用 NestedScrollView 来创建可滚动的容器。
    2. 使用垂直线性布局 (LinearLayout) 来嵌套多个部分。你可以在线性布局中添加更多的子视图来包含其他部分。
    3. 使用水平的 RecyclerView 来显示横向的 Banner。你需要创建相应的适配器和数据来填充 Banner。
    4. 使用 GridView 来显示网格视图。你可以在代码中设置适配器并提供数据。
    5. 使用 RecyclerView 来显示列表视图。同样,你需要创建适配器和提供数据。

    请根据你的实际需求创建适当的适配器和填充数据,以便每个部分显示正确的内容。这个布局示例提供了一种将不同类型的内容嵌套在 NestedScrollView 中的方法,以实现多个部分的滚动。

  • 相关阅读:
    【Java】全套云HIS(医院信息管理系统)源码包含EMR、LIS
    Nginx | nginx配置https
    XDOJ-267 判断栈输出顺序正确与否
    React 入门:组件化编码流程(一)拆分组件
    解密Spring Cloud LoadBalancer:实现高效负载均衡的魔法密卷(二)
    详细说明static关键字,各种使用场景以及作用
    git push超过100MB大文件失败(remote: fatal: pack exceeds maximum allowed size)
    GPIO子系统编写LED灯的驱动、linux内核定时器
    内网开发之后端配置前端项目流程
    R 语言nutrient数据集的可视化
  • 原文地址:https://blog.csdn.net/GYBIN02/article/details/132836189