3月7号Android开发学习

相对布局RelativeLayout

相对布局的下级视图由其他视图决定,用于确定下级视图位置的参照物分两种:

(1)与该视图自身平级的视图

(2)该视图的上级视图

如果不设定下级视图的参照物,那么下级视图默认显示在RelativeLayout内部的左上角

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    >

    <TextView
        android:id="@+id/tv_center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#ffffff"
        android:text="我在中间"
        android:textColor="#000000"
        android:textSize="11sp"></TextView>
    <TextView
        android:id="@+id/tv_center_Horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="#ffffff"
        android:text="我在水平中间"
        android:textColor="#000000"
        android:textSize="11sp"></TextView>
    <TextView
        android:id="@+id/tv_center_vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:background="#ffffff"
        android:text="我在垂直中间"
        android:textColor="#000000"
        android:textSize="11sp"></TextView>
    <TextView
        android:id="@+id/tv_align_parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:background="#ffffff"
        android:text="我在上级的左边对齐"
        android:textColor="#000000"
        android:textSize="11sp"></TextView>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="#ffffff"
        android:text="我在上级的右边对齐"
        android:textColor="#000000"
        android:textSize="11sp"></TextView>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#ffffff"
        android:text="我在上级的地部对齐"
        android:textColor="#000000"
        android:textSize="11sp"></TextView>
    


</RelativeLayout>

 网格布局GridLayout

网格布局支持多行多列的表格排列

网格布局默认从左往右,从上到下排列,它新增了两个属性:

columnCout属性,指定网格的列数

rowCount属性,指定网格的行数

滚动视图ScrollView

滚动视图有两种:

Scrollview,它是水平方向的滚动视图,垂直方向滚动时,layout_width属性值设置为match_parent,layout_height属性值设置为wrap_content

HorientationScorllView,它是水平方向的滚动视图,水平方向滚动时,layout_width属性值设置为wrap_content,layout_height属性值设置为match_parent

<?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"
    android:gravity="center">


    <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="#DA5D5D"></View>
            <View
                android:layout_width="300dp"
                android:layout_height="match_parent"
                android:background="#3C9FCC"></View>
        </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="#D586E3"></View>

            <View
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:background="#72EC77"></View>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

 

posted @ 2023-03-11 10:55  辞楠  阅读(18)  评论(0)    收藏  举报