滚动视图ScrollView

activity_scroll_view.xml

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

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

        <!-- 水平方向的线性布局,两个子视图的颜色分别为青色和黄色 -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <View
                android:layout_width="300dp"
                android:layout_height="match_parent"
                android:background="#aaffff"
                android:contentDescription="青色视图" />
            <View
                android:layout_width="300dp"
                android:layout_height="match_parent"
                android:background="#ffff00"
                android:contentDescription="黄色视图" />

        </LinearLayout>

    </HorizontalScrollView>
    
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- 垂直方向的线性布局,两个子视图的颜色分别为绿色和橙色 -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <View
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:background="#00ff00"
                android:contentDescription="青色视图" />
            <View
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:background="#ffffaa"
                android:contentDescription="黄色视图" />

        </LinearLayout>

    </ScrollView>

</LinearLayout>

AndroidManifest.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">
        <activity
            android:name=".ScrollViewActivity"
            android:exported="true" />

        <intent-filter>
            <action android:name="android/intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </application>

</manifest>
相关推荐
Moe48812 分钟前
ConcurrentHashMap 重要方法实现原理和源码解析(二)
java·后端
有梦想的攻城狮28 分钟前
初识Rust语言
java·开发语言·rust
小虾米 ~43 分钟前
RocketMQ DefaultMQPushConsumer vs DefaultLitePullConsumer
java·rocketmq·java-rocketmq
q***216044 分钟前
【监控】spring actuator源码速读
java·spring boot·spring
Kuo-Teng1 小时前
LeetCode 142: Linked List Cycle II
java·算法·leetcode·链表·职场和发展
Moe4881 小时前
ConcurrentHashMap 重要方法实现原理和源码解析(一)
java·后端
拾忆,想起1 小时前
Dubbo核心架构全解析:构建微服务通信的高速公路
java·微服务·云原生·架构·dubbo·哈希算法
楠枬2 小时前
Spring Cloud 概述
java·spring cloud·微服务
♡喜欢做梦2 小时前
MyBatis操作数据库(入门)
java·数据库·mybatis
q***d1732 小时前
微服务与单体架构的成本对比
java·微服务·架构