Android_仿制清单_1_初始布局练习_粗糙的课程表界面

本文介绍了一种使用HorizontalScrollView和ScrollView实现水平和垂直滚动效果的方法。通过嵌套这两个组件,可以展示多列并允许用户在不同方向上滚动查看内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现效果:

能够左右,上下滚动
这里写图片描述

涉及知识点:

  • HorizontalScrollView、ScrollView

布局文件:

week_show.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="周一"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="体育(4)\n@软件园体育网球\n4-1"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="操作系统(双语)\n@软件园1区305"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="计算机组织与结构课程设计@"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f90f"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f90f"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />
                    </LinearLayout>

                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="周一"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="体育(4)\n@软件园体育网球\n4-1"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="操作系统(双语)\n@软件园1区305"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="计算机组织与结构课程设计@"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />
                    </LinearLayout>

                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="周一"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="体育(4)\n@软件园体育网球\n4-1"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="操作系统(双语)\n@软件园1区305"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="计算机组织与结构课程设计@"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />
                    </LinearLayout>

                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="周一"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="体育(4)\n@软件园体育网球\n4-1"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="操作系统(双语)\n@软件园1区305"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="计算机组织与结构课程设计@"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />
                    </LinearLayout>

                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="周一"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="体育(4)\n@软件园体育网球\n4-1"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="操作系统(双语)\n@软件园1区305"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="计算机组织与结构课程设计@"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />
                    </LinearLayout>

                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="周一"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="体育(4)\n@软件园体育网球\n4-1"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="操作系统(双语)\n@软件园1区305"
                            android:textSize="20sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:minHeight="@dimen/minCHeight"
                            android:text="计算机组织与结构课程设计@"
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />

                        <TextView
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="#f0f9ff"
                            android:minHeight="@dimen/minCHeight"
                            android:text=""
                            android:textSize="24sp" />
                    </LinearLayout>

                </RelativeLayout>
            </LinearLayout>

        </ScrollView>
    </HorizontalScrollView>


</LinearLayout>

其他:

没什么难的..就是在于两个方向的滑动View的嵌套。但这个貌似不能实现任意方向的移动,这个在后期需要做一下相关的改进。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值