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

盒子模型

<!--
        内边距 padding 内容与其边框的间距 
    有上下左右 只能是正数
    安卓弱化了边框的概念
    内边距是用来修改控件的大小的
    -->

    <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">
<!--    表格可以定义行和列 ,但Table只能定义行不能定义列 -->
<!--    TableRow不需要定义宽高 -->
<!--    更推荐用linearLayout来代替 -->
    <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

<!--     输入框.
        hint提示信息,
        editable是否可编辑
        maxLeng输入最大位数 
        inputTypes输入的类型 数字number 密码textPassword 并且可以根据输入的类型输出键盘类型-->
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="请输入QQ"
        android:text="请输入"  
        android:editable="false"
        android:maxLength="10"
        android:inputType="number"
        />
<!--    多行输入框
    lines输入行数
    grivity控件内容位置
    paddingLefj控件内容的间隔-->
    <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"
        /> 
    多选一
    <!--         三种情形以上,就适用RadioButton -->
    <!--    checked为真默认选中 -->
    <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="香蕉"
        />     

进度条

<!--    有进度的进度条,总的进度max int大小不限定的整数
              设置当前进度值,progressbar
 -->
    <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"/>

<!--     星星进度条,默认五星
    reting默认星数
    stepSize默认=0.5
 -->
    <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"
        />

滑动控件

<!--
 scrollbars可以设置滑动块  HorizontalScrollView是横向滑动
    scrollbarsStyle设置滑动块样式  滑动条在界面内部/外部/悬浮
    如果scrollbars内部没有
    ScrollView是ViewGroup的子类,所以可嵌套其他子控件 ,但只能嵌套一个 否则报错  结局方案是在外面再用一个线性布局嵌套
-->
<!--     fillViewport设置滑动条占满屏幕
    ScrollView是上下滑动的控件,为了让子控件与其相同
    必须设置fillviewport为true
    而其子类必须为match parent -->
<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"/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值