Android基础_基础布局和基础控件(一)

盒子模型



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" 
        android:background="#F00"
        android:paddingLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="48dp"
        android:background="#F00"
        android:layout_marginLeft="20dp"
        android:text="@string/hello_world" />

五大布局

//      ViewGroup继承了View 
//      但他是其他容器控件的父容器,一般不会在布局直接使用,因为它不知道把子容器放到哪里去
//      所以我们使用ViewGroup的子类
//      面试题:什么是五大布局
//      ViewGroup 组视图

//          1.LinearLayout 线性布局
//          2.RelativeLayout 相对布局

//          3.FrameLayout 祯布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


//          4.AbsoluteLayout 绝对布局
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="100dp"
        android:layout_y="100dp"
        android:text="@string/hello_world" />
AbsoluteLayout>

//          5.TableLayout 表格布局
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <TableRow >
            <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="性别:" />
            <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="#F08"
        android:text="输入框" />
    TableRow>
    <TableRow >
            <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="性别:" />
            <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="#F08"
        android:text="输入框" />
    TableRow>
    <TableRow >
            <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="身份证:" />
            <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="#F08"
        android:text="输入框" />
    TableRow>

TableLayout>

EditText


    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="请输入QQ"
        android:text="请输入"  
        android:editable="false"
        android:maxLength="10"
        android:inputType="number"
        />

    <EditText 
        android:id="@+id/et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入QQ"
        android:lines="4"
        android:paddingLeft="20dp"
        />

选择框

     是非选择框
     <ToggleButton
        android:id="@+id/toggleBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textOn="哼"
        android:textOff="哈"
        android:checked="true"
        /> 
    多选一
    
    
    <RadioGroup 
        android:id="@+id/group_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >           
        <RadioButton
            android:id="@+id/apple_rb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="苹果"
            />
        <RadioButton
            android:id="@+id/banana_rb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="香蕉"
            />
        <RadioButton
            android:id="@+id/wtf_rb"
            android:checked="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="番石榴"
            />
    RadioGroup>
    多选多
        <CheckBox
        android:id="@+id/apple_CB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="苹果"
        />
    <CheckBox
        android:id="@+id/banana_CB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="香蕉"
        />     

进度条


    <ProgressBar
        android:id="@+id/progressBar4"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:max="5000"
        android:progress="300"
        />

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="5000" 
        android:progress="3009"/>


    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:numStars="10"
        android:rating="9.5"
        android:stepSize="0.1"
        />

滑动控件



<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbars="none" >

日期和时间选择器

    <DatePicker
        android:id="@+id/date1" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <TimePicker 
        android:id="@+id/tp1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

你可能感兴趣的:(android基础)