ScrollView 滚动视图

在一个屏幕的像素显示不全时,可以采用滚动视图的方式滚动显示其它内容在UI上

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <Button
            android:id="@+id/IVButton_Id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="跳转到ImageView"
            android:textSize="20dp"
            android:textAllCaps="false"/>
        <Button
            android:id="@+id/LVButton_Id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="跳转到ListView"
            android:textSize="20dp"
            android:textAllCaps="false"/>
        <Button
            android:id="@+id/GVButton_Id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="跳转到GridView"
            android:textSize="20dp"
            android:textAllCaps="false"/>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="按钮1"
            android:textSize="20dp"
            android:textAllCaps="false"
            android:layout_marginTop="100dp"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="按钮2"
            android:textSize="20dp"
            android:textAllCaps="false"
            android:layout_marginTop="100dp"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="按钮3"
            android:textSize="20dp"
            android:textAllCaps="false"
            android:layout_marginTop="300dp"/>
    </LinearLayout>

</ScrollView>

不用ScrollView时的代码,用来与ScrollView的效果对比

<?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">
<Button
android:id="@+id/IVButton_Id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转到ImageView"
android:textSize="20dp"
android:textAllCaps="false"/>
<Button
android:id="@+id/LVButton_Id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转到ListView"
android:textSize="20dp"
android:textAllCaps="false"/>
<Button
android:id="@+id/GVButton_Id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转到GridView"
android:textSize="20dp"
android:textAllCaps="false"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮1"
android:textSize="20dp"
android:textAllCaps="false"
android:layout_marginTop="100dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮2"
android:textSize="20dp"
android:textAllCaps="false"
android:layout_marginTop="100dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮3"
android:textSize="20dp"
android:textAllCaps="false"
android:layout_marginTop="300dp"/>
</LinearLayout>
发布了25 篇原创文章 · 获赞 2 · 访问量 823

猜你喜欢

转载自blog.csdn.net/yangjinjingbj/article/details/104046233