第五章 基于视图的用户界面设计

使用基础试图

一.      TextCiew视图——最基础的视图

当创建一个新Android项目时,Android Studio总是会创建activity_main.xml文件,其中包含一个<TextView>元素

使用TextView视图为用户显示文本

若需要用户编辑显示的文本,则可以使用TextView的子类EditText

二.     


(1)             Button——表示一个按钮部件

(2)             ImageButton——和Button视图相似,除了他可以显示图片

(3)             EditText——TextView视图的子类,允许用户编辑他的文本内容

(4)             CheckBox——一种具有两种状态的特殊按钮,选中 非选中

(5)             RadioGroup和RadioButton——RadioButton有两种状态:选中或非选中。RadioGroup用来组织一个或多个RadioButton视图,且在RadioGroup中只允许一个RadioButton被选中

(6)             ToggleButton——一种用来显示选中或非选中状态的轻量级指示器



三.      使用基础视图

<?xml
version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
android:layout_width="fill_parent"
   
android:layout_height="fill_parent"
    android:orientation="vertical"
>
    <Button
android:id="@+id/btnSave"
       
android:layout_width="fill_parent"
       
android:layout_height="wrap_content"
        android:text="save" />
    <Button
android:id="@+id/btnOpen"
        android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
        android:text="Open" />
    <ImageButton
android:id="@+id/btnImg1"
       
android:layout_width="fill_parent"
       
android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
/>
    <EditText
android:id="@+id/txtName"
       
android:layout_width="fill_parent"
       
android:layout_height="wrap_content" />
    <CheckBox
android:id="@+id/chkAutosave"
       
android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Autosave" />
    <CheckBox
android:id="@+id/star"
       
style="?android:attr/starStyle"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content" />
    <RadioGroup android:id="@+id/rdbGp1"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:orientation="horizontal" >
        <RadioButton
android:id="@+id/rdb1"
           
android:layout_width="fill_parent"
           
android:layout_height="wrap_content"
            android:text="Option 1"
/>
        <RadioButton
android:id="@+id/rdb2"
           
android:layout_width="fill_parent"
           
android:layout_height="wrap_content"
            android:text="Option 2"
/>
    </RadioGroup>
    <ToggleButton
android:id="@+id/toggle1"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content" />
</LinearLayout>


四.      ProgressBar视图

该视图为一些正在进行中的任务提供视觉反馈,如 在后台运行一个任务。例如:当从网络中下载数据时,需要告知用户当前的下载状态,在这种情况下,ProgressBar视图是一个很好的选择

使用该视图:

<?xml
version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
android:layout_width="fill_parent"
   
android:layout_height="fill_parent"
    android:orientation="vertical"
>
    <ProgressBar
android:id="@+id/progressbar"
       
android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       
style="@android:style/Widget.ProgressBar.Horizontal" />
</LinearLayout>


五.      AutoCompleteTextView视图

该视图类似于EditText(实际上它就是EditText的子类)除了它能在用户输入文本时自动显示一个提示列表

使用AutoCompleteTextView视图:

<?xml
version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
   
android:layout_height="fill_parent"
    android:orientation="vertical"
>
    <TextView
       
android:layout_width="fill_parent"
       
android:layout_height="wrap_content"
        android:text="Name of
President" />
    <AutoCompleteTextView
android:id="@+id/txtCountries"
       
android:layout_width="fill_parent"
       
android:layout_height="wrap_content" />
</LinearLayout>


使用选择器视图

六.      TimePicker视图

该视图允许24小时模式或者AM/PM模式选择时间

使用该视图:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
android:layout_width="fill_parent"
   
android:layout_height="fill_parent"
    android:orientation="vertical"
>
    <Button
android:id="@+id/btnSet"
       
android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I am all set!"
        android:onClick="onClick"
/>
    <TimePicker
android:id="@+id/timePicker"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content" />
</LinearLayout>



package com.cwx.basicviews4;
import
android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import
android.widget.TimePicker;
import
android.widget.Toast;
public class MainActivity
extends AppCompatActivity {
    TimePicker timePicker;
    /** Called when the activity is first
created. */
    @Override
    public void onCreate(Bundle
savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        timePicker = (TimePicker)
findViewById(R.id.timePicker);
        timePicker.setIs24HourView(true);
    }
    public void onClick(View view) {
        Toast.makeText(getBaseContext(),
                "Time selected:" +
                        timePicker.getHour() +
                        ":" +
timePicker.getMinute(),
                Toast.LENGTH_SHORT).show();
    }
}

*注意:getHour()24小时格式返回小时数值


package com.cwx.basicviews4;
import
android.app.DialogFragment;
import android.os.Bundle;


#设计#
全部评论

相关推荐

06-13 17:33
门头沟学院 Java
顺序不记了,大致顺序是这样的,有的相同知识点写分开了1.基本数据类型2.基本数据类型和包装类型的区别3.==和equals区别4.ArrayList与LinkedList区别5.hashmap底层原理,put操作时会发生什么6.说出几种树型数据结构7.B树和B+树区别8.jvm加载类机制9.线程池核心参数10.创建线程池的几种方式11.callable与runnable区别12.线程池怎么回收线程13.redis三剑客14.布隆过滤器原理,不要背八股,说说真正使用时遇到了问题没有(我说没有,不知道该怎么回答了)15.堆的内存结构16.自己在写项目时有没有遇见过oom,如何处理,不要背八股,根据真实经验,我说不会17.redis死锁怎么办,watchdog机制如何发现是否锁过期18.如何避免redis红锁19.一个表性别与年龄如何加索引20.自己的项目的QPS怎么测的,有没有真正遇到大数量表21.说一说泛型22.springboot自动装配原理23.springmvc与springboot区别24.aop使用过嘛?动态代理与静态代理区别25.spring循环依赖怎么解决26.你说用过es,es如何分片,怎么存的数据,1000万条数据怎么写入库中27.你说用limit,那么在数据量大之后,如何优化28.rabbitmq如何批次发送,批量读取,答了延迟队列和线程池,都不对29.计网知不知道smtp协议,不知道写了对不对,完全听懵了30.springcloud知道嘛?只是了解反问1.做什么的?短信服务,信息量能到千万级2.对我的建议,基础不错,但是不要只背八股,多去实际开发中理解。面试官人不错,虽然没露脸,但是中间会引导我回答问题,不会的也只是说对我要求没那么高。面完问我在济宁生活有没有困难,最快什么时候到,让人事给我聊薪资了。下午人事打电话,问我27届的会不会跑路,还在想办法如何使我不跑路,不想扣我薪资等。之后我再联系吧,还挺想去的😭,我真不跑路哥😢附一张河科大幽默大专图,科大就是大专罢了
查看30道真题和解析
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务