UI(base)-2

来源:互联网 发布:淘宝购物车营销靠谱吗 编辑:程序博客网 时间:2024/04/28 07:45

ImageView:直接继承自View,它的作用就是在街面上显示图片
(它能显示的不仅仅是图片,任何Drawable对象都可以使用ImageView来显示)
代码示例:

  <ImageView        android:layout_width="60dp"        android:layout_height="60dp"        android:src ="@drawable/wifi"        android:background="#f00"        android:scaleType="centerCrop"        />

多选框控件 CheckBox
CheckBox:直接继承自Button,它的作用就是在界面提供一组选项,可以多选。
示例代码:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.asong.testui2.MainActivity">    <ImageView        android:layout_width="60dp"        android:layout_height="60dp"        android:src ="@drawable/wifi"        android:background="#f00"        android:scaleType="centerCrop"        /><LinearLayout    android:layout_width="match_parent"    android:layout_height="wrap_content">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="喜欢的颜色"        />    <CheckBox        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="红色"        android:checked="true"        //默认选中,每一个checkbox都能设置这种属性        />    <CheckBox        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="蓝色"        />    <CheckBox        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="绿色"        />    <CheckBox        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="紫色"        />    <CheckBox        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="黄色"        /></LinearLayout></LinearLayout>

单选框控件:RadioButton
直接继承自Button,提供一组选项,只能单选。
RadioButton要和RadioGroup一起使用
示例代码:

    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical">        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="您的性别是:"            />        <RadioGroup            android:orientation="horizontal"            android:layout_width="wrap_content"            android:layout_height="wrap_content">        <RadioButton            android:id="@+id/btn_m"            android:checked="true"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="男"            />        <RadioButton            android:id="@+id/btn_f"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="女"            />        </RadioGroup>    </LinearLayout>
0 0
原创粉丝点击