Android 视图View的基本属性

来源:互联网 发布:c语言编程求最简分数 编辑:程序博客网 时间:2024/06/06 00:21

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"

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


原创粉丝点击