山东大学项目实训-地图圈系统-APP(2)

山东大学项目实训-地图圈系统-APP(2),第1张

概述文章目录安卓开发中的常见控件1.EditText---输入文本2.TextView3.Button4.CheckBox---复选框5.RadioButton---单选按钮6.ProgressBar7.ImageView8.ListViewArrayAdapter:SimpleAdapter:安卓开发中的常见控件1.EditText—输入文本​常见属性android:hint="提示输

文章目录安卓开发中的常见控件1.EditText---输入文本2.TextView3.Button4.CheckBox---复选框5.RadioButton---单选按钮6.ProgressBar7.ImageView8.ListViewArrayAdapter:SimpleAdapter:

安卓开发中的常见控件1.EditText—输入文本

​ 常见属性

androID:hint="提示输入的内容"androID:textcolorHint="设置提示hint信息的颜色"androID:maxLength="输入最长的长度"androID:maxlines="输入最长的行数"androID:minLength="输入最短的长度"androID:inputType="输入数据类型"//文章过滤设置    androID:inputType="text"//输入文本    androID:inputType="textPassword"//输入密码    androID:inputType="textVisiblePassword"//输入可见的密码    androID:inputType="number"//输入数字    androID:inputType="phone"//拨号键盘

​ 实例:

<?xml version="1.0" enCoding="utf-8"?><linearLayout    androID:layout_height="match_parent"    androID:layout_wIDth="match_parent"    androID:orIEntation="vertical"    xmlns:androID="http://schemas.androID.com/apk/res/androID"    >    <EditText        androID:ID="@+ID/editText_one"        androID:inputType="number"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:maxLength="11"        androID:hint="请在此输入手机号码"        androID:textcolorHint="	#4B0082"/>    <EditText        androID:ID="@+ID/editText_two"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:maxLength="8"        androID:hint="输入密码"        androID:textcolorHint="	#87CEFA"        androID:inputType="textPassword"/></linearLayout>

​ 效果图:

2.TextVIEw

​ 常见属性

androID:textcolor="文本颜色"androID:textSize="文本大小"//sp为单位androID:background="背景颜色 || 图片地址"androID:text="文本内容"  //设置文本位置androID:gravity="center_vertical" //设置垂直居中androID:gravity="right" //设置居右androID:gravity="center_vertical|center_horizontal" //设置垂直水平居中  //设置链接androID:autolink="all"     //设置自动识别链接所有androID:autolink="phone"     //设置自动识别链接,phone为链接到电话簿androID:autolink="email"     //设置自动识别链接,phone为链接到邮箱androID:autolink="web"     //设置自动识别链接,phone为链接到web网址  //文本过长处理androID:ellipsize="start" 省略号在开头androID:ellipsize="mIDdle" 省略号在中间androID:ellipsize="end" 省略号在结尾androID:ellipsize="marquee"设置跑马灯效果 //设置字形androID:textStyle="bold|italic"

​ 实例:

<?xml version="1.0" enCoding="utf-8"?><linearLayout    androID:layout_height="match_parent"    androID:layout_wIDth="match_parent"    androID:orIEntation="vertical"    xmlns:androID="http://schemas.androID.com/apk/res/androID"    >    <TextVIEw        androID:ID="@+ID/textVIEw0"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:textcolor="#FF0000"        androID:textSize="18sp"        androID:background="#FFFFFF"        androID:text="拨打手机:186621422541"        androID:gravity="center_vertical"        androID:autolink="phone" />        </linearLayout>

​ 效果图:

3.button

​ 常见属性

androID:textAllCaps="false"//大写androID:background="#00ffff"//颜色androID:onClick="goClick"//点击监听androID:text="button"//按钮上显示的内容

​ 监听

//匿名内部类方式建立的监听器button.OnClickListener anonymousListener=new VIEw.OnClickListener() {    @OverrIDe    public voID onClick(VIEw v) {        System.out.println("匿名内部类方式定义的的button监听器!");        Toast.makeText(MainActivity.this, "匿名内部类方式定义的的button监听器!", Toast.LENGTH_SHORT).show();    }};button btn=(button)findVIEwByID(R.ID.btnForth);btn.setonClickListener(anonymousListener);
//利用Activity类实现监听接口public class MainActivity extends Activity implements VIEw.OnClickListener{     @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.layoutbutton);        //设立由Activity实现OnClickListener接口的共同的监听器,多次设置会覆盖以前的值        btnFirst.setonClickListener(this);        btnSecond.setonClickListener(this);    }      //利用Activity类实现监听接口    @OverrIDe    public voID onClick(VIEw v) {        switch (v.getID()) {//区分哪个按钮的事件            case R.ID.btnFirst:                System.out.println("First button");                Toast.makeText(MainActivity.this, "First button", Toast.LENGTH_SHORT).show();                break;            case R.ID.btnSecond:                System.out.println("Second button");                Toast.makeText(MainActivity.this, "Second button", Toast.LENGTH_SHORT).show();                break;        }    }}
4.CheckBox—复选框

​ 常见属性

androID:text="美术"androID:ID="@+ID/like3"androID:checked="true"//是否选中

​ 监听:

public class MainActivity extends AppCompatActivity {    EditText editText;    private Compoundbutton.OnCheckedchangelistener checkBox_Listener;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        checkBox_Listener=new Compoundbutton.OnCheckedchangelistener() {            @OverrIDe            public voID onCheckedChanged(Compoundbutton buttonVIEw, boolean isChecked) {                if(isChecked){                    Log.i("check", "选中了["+buttonVIEw.getText().toString()+"]");                    Toast.makeText(MainActivity.this, buttonVIEw.getText().toString()+"]", Toast.LENGTH_SHORT).show();                }            }        };        final CheckBox like1=(CheckBox)findVIEwByID(R.ID.like1);        final CheckBox like2=(CheckBox)findVIEwByID(R.ID.like2);        final CheckBox like3=(CheckBox)findVIEwByID(R.ID.like3);        like1.setonCheckedchangelistener(checkBox_Listener);        like2.setonCheckedchangelistener(checkBox_Listener);        like3.setonCheckedchangelistener(checkBox_Listener);                button button=(button)findVIEwByID(R.ID.button1);        button.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw arg0) {                String like="";//保存选中的值                if(like1.isChecked()){                    like+=like1.getText().toString()+"";//当第一个复选框被选中                }                if(like2.isChecked()){                    like+=like2.getText().toString()+"";//当第二个复选框被选中                }                if(like3.isChecked()){                    like+=like3.getText().toString()+"";//当第三个复选框被选中                }                //显示被选中的复选框                Toast.makeText(MainActivity.this, like, Toast.LENGTH_SHORT).show();            }        });    }}
5.Radiobutton—单选按钮

Radiobutton需要放在RadioGroup中

​ 常见属性

androID:text="男"

​ 实例:

<?xml version="1.0" enCoding="utf-8"?><linearLayout    androID:layout_height="match_parent"    androID:layout_wIDth="match_parent"    androID:orIEntation="vertical"    xmlns:androID="http://schemas.androID.com/apk/res/androID"    >    <RadioGroup        androID:ID="@+ID/sex"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:orIEntation="vertical">        <Radiobutton            androID:ID="@+ID/male"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="男" />        <Radiobutton            androID:ID="@+ID/female"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="女"            />    </RadioGroup>    <button        androID:ID="@+ID/button"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"         androID:text="选择"/></linearLayout>

​ 监听:

public class MainActivity extends AppCompatActivity {    EditText editText;    private Compoundbutton.OnCheckedchangelistener checkBox_Listener;    button button;    RadioGroup radioGroup;    Radiobutton radiobutton1;    Radiobutton radiobutton2;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        radioGroup=findVIEwByID(R.ID.sex);        radiobutton1=findVIEwByID(R.ID.male);        radiobutton2=findVIEwByID(R.ID.female);        button=findVIEwByID(R.ID.button);        radioGroup.setonCheckedchangelistener(new RadioGroup.OnCheckedchangelistener() {            @OverrIDe            public voID onCheckedChanged(RadioGroup group, int checkedID) {                switch (checkedID){                    case R.ID.male:                        Boolean flag=radiobutton1.isChecked();                        if(radiobutton1.isChecked()) {                            Log.i("sex", "你是: " + radiobutton1.getText().toString());                        }                        break;                    case R.ID.female:                        if(radiobutton2.isChecked()) {                            Log.i("sex", "你是: " + radiobutton2.getText().toString());                        }                        break;                }            }        });        button.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                String sex="";                if(radiobutton1.isChecked()){                    sex=radiobutton1.getText().toString();                }                if(radiobutton2.isChecked()){                    sex=radiobutton2.getText().toString();                }                Log.i("hhh",sex);            }        });    }}
6.Progressbar

​ 常见属性

//设置进度条类型  //水平直线进度条       //大的环形进度条       //小的环形进度条  //设置第一进度和第二进度androID:progress="第一进度的当前值"androID:secondaryProgress="第二进度的当前值"  //设置进度的最大值androID:max="100"  //设置进度条的显示状态androID:visibility="gone"
7.ImageVIEw

​ 常见属性

androID:adjustVIEwBounds="true"    //是否按比例缩小androID:maxWIDth="150dp"androID:maxHeight="150dp"androID:src="@drawable/second" //图片地址androID:scaleType=	center//按图片的原来 size 居中显示,当图片长/宽超过VIEw的长/宽,则截取图片的居中部分显示	centerCrop//按比例扩大图片的size居中显示,使得图片长(宽)等于或大于VIEw的长(宽)	centerInsIDe//将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于VIEw的长/宽	fitCenter//把图片按比例扩大/缩小到VIEw的宽度,居中显示	fitStart//把图片按比例扩大/缩小到VIEw的宽度,置于顶部显示	fitEnd//把图片按比例扩大/缩小到VIEw的宽度,置于底部显示	fitXY//不按比例缩放图片,目标是把图片塞满整个VIEw	matrix//从ImageVIEw左上角开始直接显示,显示不全时,裁剪
8.ListVIEw

​ 首先需要了解适配器,适配器就是在安卓中,把数据变成符合界面风格的形式,并且通过ListVIEw显示出来

​ 三种常见的适配器:

(1)ArrayAdapter:简单的数据映射,只包含文字数据。

(2)SimpleAdapter:文字和图片映射,内容相对丰富。

(3)自定义的Adapter

ArrayAdapter:

第一步:编写activity_main.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout    androID:layout_height="match_parent"    androID:layout_wIDth="match_parent"    androID:orIEntation="vertical"    xmlns:androID="http://schemas.androID.com/apk/res/androID"    >    <TextVIEw        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="ArrayAdapter ListVIEw" />    <ListVIEw        androID:ID="@+ID/simpleListVIEwControll"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content" /></linearLayout>

第二步:在Activity中写数据

//用已有的样式public class MainActivity extends AppCompatActivity {    //定义ListVIEw对象变量---VIEw    private ListVIEw ListvIEw;    //存放数据的List<String>对象---Model    private List<String> List;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        //获取ListVIEw对象        ListvIEw=(ListVIEw)findVIEwByID(R.ID.simpleListVIEwControll);        //定义List变量(提供数据)--ArrayList是List的具体实现        List=new ArrayList<String>();        //添加数据内容        List.add("测试数据--1");        List.add("测试数据--2");        List.add("测试数据--3");        List.add("测试数据--4");        List.add("测试数据--5");        List.add("测试数据--6");        List.add("测试数据--7");        List.add("测试数据--8");        List.add("测试数据--9");        //定义ArrayAdapter,衔接ListVIEw和List---Controller        //参数-----上下文环境, ListVIEw的每一行的布局,  List<String>对象        //如果要使用自定义的布局,必须指明TextVIEw的ID--布局中也可以包含除TextVIEw之外的其它控件        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, androID.R.layout.simple_List_item_1, List);                //设置ListVIEw的Adapter对象        ListvIEw.setAdapter(adapter);        ListvIEw.setonItemClickListener(new AdapterVIEw.OnItemClickListener() {            @OverrIDe            public voID onItemClick(AdapterVIEw<?> parent, VIEw vIEw, int position, long ID) {                                String info=List.get(position) + "  was clicked!"; //取出点击的行的内容                Toast.makeText(MainActivity.this, info+"--"+ID, Toast.LENGTH_SHORT).show();            }        });    }}
//用自定义的样式,只需要自定义一个test.xml文件,把Java中的适配器改成如下代码ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, R.layout.test, R.ID._ID, List);
<!--test.xml--><?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="horizontal"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <TextVIEw        androID:ID="@+ID/_ID"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:textcolor="#3CB371"        androID:textSize="50sp"/></linearLayout>
系统有的xml自定义的xml

SimpleAdapter:

第一步:编写布局文件activity_main.xml,然后添加ListVIEw控件

<?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="horizontal">    <linearLayout        androID:orIEntation="vertical"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content">        <TextVIEw            androID:ID="@+ID/Title"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:textcolor="#FF000000"            androID:textSize="28sp" />        <TextVIEw            androID:ID="@+ID/info"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:textcolor="#FF000000"            androID:textSize="18sp" />    </linearLayout></linearLayout>

第二步:在Activity中修改

//使用ListActivity--内部仅含有一个ListVIEwpublic class MainActivity extends ListActivity {    //数据线性表--List实际上是一个线性表的接口    List<Map<String,Object>> List;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //创建Adapter对象        SimpleAdapter adapter = new SimpleAdapter(this, //上下文对象                getData(),               //存放数据的List对象                R.layout.activity_main,         //每行的布局                new String[]{"Title","info"},  //数据对象Map中的列名--键                new int[]{R.ID.Title,R.ID.info});  //列内容--ListvIEw中的控件ID,对应控件用于显示Map对象中的值        //为ListActivity中的ListVIEw设置Adapter        setlistadapter(adapter);    }    //获取List数据对象    private List<Map<String,Object>> getData(){        //建立List对象--具体的ArrayList对象        List=new ArrayList<Map<String,Object>>();        //List中存放的Map对象,由多个<键,值>对构成--一个Map对象对应ListVIEw中的一行        Map<String, Object> map;        map=new HashMap<String,Object>();        map.put("Title", "牛");        map.put("info", "食草动物,家畜");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "孔雀");        map.put("info", "鸟类,开屏很好看");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "熊猫");        map.put("info", "珍稀,国宝");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "恐龙");        map.put("info", "爬行类,已灭绝");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "神龙");        map.put("info", "神话中的动物");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "北极熊");        map.put("info", "生活在极寒之地");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "牛-2");        map.put("info", "食草动物,家畜");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "孔雀-2");        map.put("info", "鸟类,开屏很好看");        List.add(map);        map=new HashMap<String,Object>();        map.put("Title", "熊猫-2");        map.put("info", "珍稀,国宝");        List.add(map);        return List;    }    //重写此方法---点击一行时的回调函数--参数含义同前    @OverrIDe    protected voID onListItemClick(ListVIEw l, VIEw v, int position, long ID) {        super.onListItemClick(l, v, position, ID);        String s=List.get(position).get("Title").toString(); //获取该行的Map对象的指定属性的数据内容        Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();    }}

结果:

总结

以上是内存溢出为你收集整理的山东大学项目实训-地图圈系统-APP(2)全部内容,希望文章能够帮你解决山东大学项目实训-地图圈系统-APP(2)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1030892.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存