PS:将来的你会感谢现在奋斗的自己....

学习内容:

1.进度条

2.拖动条

3.星级评论条

1.进度条...    

  进图条这东西想必大家是很熟悉的...为了使用户不会觉得应用程序死掉了,因此为之设置一个进度条使应用程序的运行状态更好的反馈给客户...这也就是进度条的作用...因此一般的应用程序都会加入进度条...进度条分为圆形进度条和线性的进度条...目的都是一样的,只是展示的效果是不同的...用代码讲解一下...

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/TextView_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="圆形进度条..."
android:textSize="18sp"/>
<ProgressBar
android:id="@+id/progress_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"/>
<TextView
android:id="@+id/TextView_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="圆形小进度条..."
android:textSize="18sp"/>
<ProgressBar
android:id="@+id/progress_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleSmall"/>
<TextView
android:id="@+id/TextView_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="水平進度條"
android:textSize="18sp"/>
<ProgressBar
android:id="@+id/progressbar_3"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:max="200"
android:progress="50"
android:secondaryProgress="75"
style="?android:attr/progressBarStyleHorizontal"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/Button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增加..."/>
<Button
android:id="@+id/Button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="減少..."/>
</LinearLayout>
</LinearLayout>

  说一下细节的东西...这里style属性表示的是进度条是什么类型的...max表示进度条的最大值...progress表示第一级进度条的初始值...secondaryprogress表示第二级进度条的初始值...大家运行一下就能看得出来哪个是第一级哪个是第二级...然后定义了一个水平进度条,使用两个按钮来控制进度条的增加和减少...

package com.example.android_view;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_PROGRESS);//设置标题栏的进度条...
setContentView(R.layout.activity_main);
setProgressBarVisibility(true);//设置进度条的可见性,true可见 ,false不可见.. final ProgressBar progressbar_h=(ProgressBar)findViewById(R.id.progressbar_3);//获取水平进度条的id值.. setProgress(progressbar_h.getProgress()*100);//因为标题栏的进度条也是水平进度条,因此可以这样进行赋值....
setSecondaryProgress(progressbar_h.getProgress()*100);//设置标题栏的二级进度值..
Button but=(Button)findViewById(R.id.Button_1);
but.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
progressbar_h.incrementProgressBy(5);//当点击按钮时每次进度条的值都会增加5...但是要*100...
setProgress(progressbar_h.getProgress()*100);
} });
Button but_1=(Button)findViewById(R.id.Button_2);
but_1.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
progressbar_h.incrementProgressBy(-5);//这个就是-5了...同时也要*100...
setProgress(progressbar_h.getProgress()*100);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

2.拖动条...

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"/>
<SeekBar
android:id="@+id/seekbar_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

java文件...

package com.example.android_view;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends Activity {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.myTextView);
SeekBar ser=(SeekBar)findViewById(R.id.seekbar_1);
ser.setProgress(60);
tv.setText("初始值为:"+60);
/*发现了个好玩的事情,就是注册监听有很多种写法...
* OnSeekBarChangeListener osbcl=new OnSeekBarChangeListener(){
* 内部方法...
* }
* OnSeekBarChangeListener osbcl=new SeekBar.OnSeekBarChangeListener(){
* 内部方法...
* }
* OnSeekBarChangeListener osbcl=(new SeekBar.OnSeekBarChangeListener(){
* 内部方法...
* });
* 上面这三种需要注册...ser.setOnSeekBarChangeListener(osbcl); 就可以使用了...
* ser.OnSeekBarChangeListener =(new SeekBar.OnSeekBarChangeListener(){
* 内部方法...
* });
* */
//这个监听内部有三种方法...都要进行重写...
OnSeekBarChangeListener osbcl=new OnSeekBarChangeListener() {
//停止拖动时的方法...
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
MainActivity.this.tv.append("停止值为:"+seekBar.getProgress()+"\n");//字符串追加函数...将这些字符串追加到tv中...
}
//开始拖动时的方法...
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
MainActivity.this.tv.append("开始值为"+seekBar.getProgress()+"\n");
}
//改变后的方法...
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
MainActivity.this.tv.append("正在拖动,当前值为:"+seekBar.getProgress()+"\n");
}
};
ser.setOnSeekBarChangeListener(osbcl);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

3.星级评分条...

  评论条这东西,只要是和客户利益挂钩的就一定会有..评论这个东西...星级评论条是非常常见的..比如说我们在淘宝买的东西到了以后就会给卖家一个评价,这个评价是星级+文字进行评价...使更多的消费者去了解卖家的状况...从而形成信息交互...

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--rating="3"表示初始值設置為3..-->
<RatingBar
android:id="@+id/rat_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="3"/>
<RatingBar
android:id="@+id/rat_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="3"/>
<RatingBar
android:id="@+id/rat_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="3"/>
</LinearLayout>

java文件...

package android.basic.lesson11;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener; public class MainHelloRatingBar extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //定义组件对象
final RatingBar rb1 = (RatingBar)findViewById(R.id.rat_1);
final RatingBar rb2 = (RatingBar)findViewById(R.id.rat_2;
final RatingBar rb3 = (RatingBar)findViewById(R.id.rat_3); //定义评分监听器
OnRatingBarChangeListener orbcl= new OnRatingBarChangeListener(){ @Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
switch(ratingBar.getId()){
case R.id.RatingBar01:
//把第一个评分条的值取出来设置给其他评分条
rb2.setRating(rb1.getRating());
rb3.setRating(rb1.getRating()*2);//十颗星所以乘以2
break;
case R.id.RatingBar02:
rb1.setRating(rb2.getRating());
rb3.setRating(rb2.getRating()*2);
break;
case R.id.RatingBar03:
rb1.setRating(rb3.getRating()/2);
rb2.setRating(rb3.getRating()/2);
break;
}
}
} ;
//绑定监听器
rb1.setOnRatingBarChangeListener(orbcl);
rb2.setOnRatingBarChangeListener(orbcl);
rb3.setOnRatingBarChangeListener(orbcl);
}
}

总而言之,无论是进度条,拖动条,还是评分条...在应用程序中被广泛的应用...因此需要熟练掌握...

PS:最近打算做个闹钟app...祝自己成功....

                                                                                             

Android View 之进度条+拖动条+星级评论条....的更多相关文章

  1. Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar

    原文:Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar 前面两期都在学习ProgressBar的使用,关于自定义ProgressBar的内容后期会继续学习的,本期先 ...

  2. Android 自定义 View 圆形进度条总结

    Android 自定义圆形进度条总结 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 微信公众号:牙锅子 源码:CircleProgress 文中如有纰漏,欢迎大家留言指出. 最近 ...

  3. Android课程---用进度条改变图片透明度

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  4. Android——菜单和进度条

    xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...

  5. Android笔记(二十四) Android中的SeekBar(拖动条)

    拖动条和进度条非常相似,只是进度条采用颜色填充来表明进度完成的程度,而拖动条则通过滑块的位置来标识数值——而且拖动条允许用户拖动滑块来改变值,因此拖动条通常用于对系统的某种数值进行调节,比如调节音量等 ...

  6. Android -- 自定义带进度条的按钮

    1. 实现了一个带进度条的按钮,完成后显示提示信息,并设置按钮为不可再次被点击

  7. android中progress进度条的使用

    activity.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  8. Android 电池电量进度条,上下滚动图片的进度条(battery)

    最近,制作一个app,需要模拟一个电池电量的进度条,根据电量多少来设置百分比,进度条不断上下滚动,就像平时手机充电一样的电池电量进度条.我就自定义view实现了电量进度条.修改图片就可以达到自己想要的 ...

  9. Android 自学之进度条ProgressBar

    进度条(ProgressBar)也是UI界面中的一种非常使用的组件,通常用于向用户显示某个耗时完成的百分比.因此进度条可以动态的显示进度,因此避免长时间地执行某个耗时操作时,让用户感觉程序失去了响应, ...

随机推荐

  1. 翻译:微软style的并行计算

    Parallel Microsoft-Style By Andrew Binstock, July 20, 2011 Note:主要是自动翻译,俺做了小量修改 1 Comment The actor ...

  2. [算法导论]BFS @ Python

    class Graph: def __init__(self): self.V = [] class Vertex: def __init__(self, x): self.key = x self. ...

  3. 使用Dezender对zend加密后的php文件进行解密

    在开发中需要修改一些php文件,部分是通过zend加密的,记事本打开之后是这样的: 此时需要使用Dezender进行解密,下载链接如下: Dezender.7z 下载后解压到C盘(路径不要带有中文), ...

  4. jackson readTree

    String jsonstr = "{\"msg\":{\"head\":{\"version\":\"1.0\&quo ...

  5. sqlserver 生成UUID随机码

    )) ) AS BEGIN ); ,),),),),) RETURN @id END --使用如下 select dbo.[FunGetUUID32](NEWID());

  6. 【转】 IOS开发xcode报错之has been modified since the precompiled header was built

    本文转载自  IOS开发xcode报错之has been modified since the precompiled header was built 其实我是升级xcode到4.6.3的时候遇到的 ...

  7. 提高FOR插入数据库动作的优化代码

    await Task.Factory.StartNew(() => Parallel.ForEach(result.data.o, s => { sql = "insert in ...

  8. 利用VBA查找excel中一行某列第一次不为空与最后一列不为空的列数

    昨日同事有需求,想知道每个商品第一次销售的月份,以及最后一次销售的月份. 本想通过什么excel函数来解决,但是找了半天也没找到合适的,最后还是通过VBA来解决吧. 使用方法: Excel工具-宏-V ...

  9. GitHub使用简单记录

    根据<GotGitHub>[1]所做的一些整理 1. 浏览托管项目 在GitHub的页面中可以使用键盘快捷键 (1)按下问号(?)会在弹出窗口显示当前页面可用的快捷键. (2)在项目的代码 ...

  10. android中无限循环滑动的gallery实例

    android中无限循环滑动的gallery实例 1.点击图片有变暗的效果,使用imageview.setAlpha(),并且添加ontouchListener public void init() ...