Android 视图View的基本属性

View是Android的基本视图,所有的控件和布局都是从View类直接或者间接的派生而来的。所以View的基本属性和方法对所有的控件和布局是通用的,知道这些基本的属性和方法,在看其他控件和布局就容易的多了。

下面我们用一个示例来看下View都有哪些基本属性。


让我们看下代码运行效果:




然后在让我们看下滚动视图ScrollView的xml用法示例。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:gravity="center"
    tools:context="com.easygoing.day1.MainActivity">

    <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="200dp"
                android:layout_height="match_parent"
                android:background="@android:color/holo_red_dark">
            </View>

            <View
                android:layout_width="200dp"
                android:layout_height="match_parent"
                android:background="@android:color/holo_purple">
            </View>
        </LinearLayout>
    </HorizontalScrollView>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <View
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="@android:color/holo_green_dark">
            </View>
            <View
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="@android:color/holo_blue_dark">
            </View>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="我是滚动视图的文本"
                android:gravity="center"/>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

运行效果



当我们需要将scrollview视图充满屏幕的时候,需这样设置:

  android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"

然后我加了一个背景色好看清楚效果。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值