Android入门主要知识总结

Android基础

    • 资源文件
    • LinearLayout(线性布局)
    • RelativeLayout(相对布局--泡泡龙)
    • FrameLayout(帧布局--医者天下)
    • ListView(列表视图)可以作为控件也可以作为布局属性:
    • Spinner(下拉框)
    • 开关按钮控件(1.ToggleButton 2.Switch)
    • 单选框(RadioGroup)
    • 复选框(CheckBox)
    • ProgressBar(进度条) SeekBar(拖动条控件)
    • RatingBar(星星)

资源文件

在res–values目录下:

  • colors:主要放颜色
  • strings:主要放文字
  • style:主要放属性
  • dimens:主要放文字或者间距大小
  • 新建在res下的文件包:raw(主要放音乐)

android:layout_marginTop=“30dp” 上边距
android:layout_marginBottom=“40dp” 下边距
android:layout_marginLeft=“8dp” 左边距
android:layout_marginRight=“8dp” 右边距
android:background="@mipmap/background" 插背景图片
android:background="#673AB7" 背景颜色
android:src="@mipmap/welcome" 插图片

LinearLayout(线性布局)

android:orientation=“horizontal” 水平方向
android:orientation=“vertical” 垂直方向

RelativeLayout(相对布局–泡泡龙)

android:layout_above 在什么上面
android:layout_alignLeft 左对齐
android:layout_centerInParent=“true” 设置控件在父容器的正中间

FrameLayout(帧布局–医者天下)

android:scaleType=“fitXY” 让图片XY轴拉满2

ListView(列表视图)可以作为控件也可以作为布局属性:

android:divider 加入图片一定要放在drawable目录下
android:entries 数组资源来源:String里面来
android:dividerHeight=“2dp” 分割图片的高度大小

Spinner(下拉框)

属性:
android:entries 数组资源来源:String里面来

开关按钮控件(1.ToggleButton 2.Switch)

属性:
android:textOff=“关闭”
android:textOn=“开启”
Java代码:1.声明2.赋值3.给开关设置状态改变事件(setOnCheckedChangeListener)

//idChecked如果等于true 表示开启状态 (选中状态),反之  if(isChecked==true){    //图片是亮灯的     			imageView1.setImageResource(R.drawable.on);Toast.makeText(SwitchActivity.this,"灯已经开启",Toast.LENGTH_SHORT).show();}else{   //图片是关灯的   imageView1.setImageResource(R.drawable.off);Toast.makeText(SwitchActivity.this,"灯已经关闭",Toast.LENGTH_SHORT).show();} 

单选框(RadioGroup)

Java代码:1.声明2.赋值3.给RadioGroup组设置事件(setOnCheckedChangeListener)

//4.获取选中的单选框的文字
String str="";//用于装获取到的选中的文字for (int i=0;i<radioGroup.getChildCount();i++){RadioButton radioButton=(RadioButton)radioGroup.getChildAt(i);//判断当前的radioButton是否选中if (radioButton.isChecked()){ //拿文字str=radioButton.getText().toString();//结束break; }}
//5.用Toast提示显示 Toast.makeText(MainActivity.this,”你选的性别:"+str,Toast.LENGTH_SHORT).show();

复选框(CheckBox)

Java代码:1.声明2.赋值3.给按钮设置事件(setOnClickListener)

//一样利用循环
CheckBox[] checkBoxes={checkBox,checkBox2,checkBox3,checkBox4};for (int i=0;i<checkBoxes.length;i++){if(checkBoxes[i].isChecked()==true){ str+=checkBoxes[i].getText().toString()+"  ";}} 
//5.Toast提示Toast.makeText(CheackActivity.this,"你的兴趣有"+str,Toast.LENGTH_SHORT).show();}

ProgressBar(进度条) SeekBar(拖动条控件)

属性:
1.style="?android:attr/progressBarStyleHorizontal" 水平进度条(精确模式)
2.style="?android:attr/progressBarStyle" 圆圈形式进度条(不精确模式)
android:max=“255” 滑动条的最大值
android:progress=“100” 滑动条的当前值
Java代码:1.声明2.赋值3.给拖动设置事件(setOnSeekBarChangeListener)

	//拖动进度改变时(int progress:表示当前的拖动进度条)//给图片设置上透明度的属性(setAlpha(); 或者 setImageAlpha();版本的原因)  imageView.setImageAlpha(progress);//图片透明度的范围0~255//给进度条设置进度值  progressBar.setProgress(progress);}@Override public void onStartTrackingTouch(SeekBar seekBar) {//拖动进度改变之前}@Override public void onStopTrackingTouch(SeekBar seekBar) {//拖动进度改变后} 

RatingBar(星星)

属性:
android:numStars=“5” 星星个数
android:progressTint="@color/colorPrimary" 星星颜色
android:stepSize=“0.5” 点亮步数
android:rating=“5” 默认点亮星星个数
Java代码:1.声明2.赋值3设置点击事件(setOnClickListener)

String str=editText.getText().toString();//获取文本框的值 
float xx=ratingBar.getRating();//获取评分的值
String txt="你的评分内容是"+str+"\n评分是"+xx;
//用Toast提示显示  Toast.makeText(RatingBarActivity.this,txt,Toast.LENGTH_SHORT).show();


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部