茂名网站建设托管,阿里云 wordpress主机名,深圳商业网站建设,手机设计专用软件1.案例效果图 2.准备素材 progress1.png(78*78) progress2.png(78*78) 3.原理 采用一张图片作为ProgressBar的背景图片(一般采用颜色比较浅的)。另一张是进度条的图片(一般采用颜色比较深的图片)。进度在滚动时#xff1a;进度图片逐步显示#xff0c;背景图片逐… 1.案例效果图 2.准备素材 progress1.png(78*78) progress2.png(78*78) 3.原理 采用一张图片作为ProgressBar的背景图片(一般采用颜色比较浅的)。另一张是进度条的图片(一般采用颜色比较深的图片)。进度在滚动时进度图片逐步显示背景图片逐步隐藏达到上面的效果。 4.灵感来自Android控件提供的源码 4.1 默认带进度的进度条如下图 [html] view plaincopyprint? ProgressBar android:idid/progressBar2 styleandroid:style/Widget.ProgressBar.Horizontal android:layout_width268dp android:layout_heightwrap_content android:progress45 / ProgressBarandroid:idid/progressBar2styleandroid:style/Widget.ProgressBar.Horizontalandroid:layout_width268dpandroid:layout_heightwrap_contentandroid:progress45 / 注意关键是style属性在起作用 4.2 找到样式定义的位置 鼠标放在style属性值上按下Ctrl键出现超链接点击超链接跳转到样式的定义位置 样式定义的内容如下 重点研究 android:progressDrawable进度条的样式 android:drawable/progress_horizontal样式定义的文件 在android-sdk-windows\platforms\android-14\data\res目下搜索progress_horizontal.xml文件搜索结果如下 打开progress_horizontal.xml文件内容如下 [html] view plaincopyprint? layer-listxmlns:androidlayer-listxmlns:androidhttp://schemas.android.com/apk/res/android itemandroid:iditemandroid:idandroid:id/background shape cornersandroid:radiuscornersandroid:radius5dip/ gradient android:startColor#ff9d9e9d android:centerColor#ff5a5d5a android:centerY0.75 android:endColor#ff747674 android:angle270 / /shape /item itemandroid:iditemandroid:idandroid:id/secondaryProgress clip shape cornersandroid:radiuscornersandroid:radius5dip/ gradient android:startColor#80ffd300 android:centerColor#80ffb600 android:centerY0.75 android:endColor#a0ffcb00 android:angle270 / /shape /clip /item itemandroid:iditemandroid:idandroid:id/progress clip shape cornersandroid:radiuscornersandroid:radius5dip/ gradient android:startColor#ffffd300 android:centerColor#ffffb600 android:centerY0.75 android:endColor#ffffcb00 android:angle270 / /shape /clip /item /layer-list layer-listxmlns:androidhttp://schemas.android.com/apk/res/android itemandroid:idandroid:id/backgroundshapecornersandroid:radius5dip/gradientandroid:startColor#ff9d9e9dandroid:centerColor#ff5a5d5aandroid:centerY0.75android:endColor#ff747674android:angle270//shape/item itemandroid:idandroid:id/secondaryProgressclipshapecornersandroid:radius5dip/gradientandroid:startColor#80ffd300android:centerColor#80ffb600android:centerY0.75android:endColor#a0ffcb00android:angle270//shape/clip/item itemandroid:idandroid:id/progressclipshapecornersandroid:radius5dip/gradientandroid:startColor#ffffd300android:centerColor#ffffb600android:centerY0.75android:endColor#ffffcb00android:angle270//shape/clip/item/layer-list 释义 item android:idandroid:id/background定义进度条的背景样式 item android:idandroid:id/secondaryProgress辅助进度条的样式 item android:idandroid:id/progress进度条的样式 思考如果我想做垂直进度条怎么办了 关键在clip元素的属性上做修改 clipandroid:clipOrientationvertical 定义滚动的方向 vertical为垂直方向android:drawabledrawable/progress1 定义进度的图片 android:gravitybottom 定义进度的开始位置 /clip 5.定义样式文件progress_vertical.xml progress_vertical.xml文件代码如下 [html] view plaincopyprint? ?xmlversionxmlversion1.0encodingutf-8? layer-listxmlns:androidlayer-listxmlns:androidhttp://schemas.android.com/apk/res/android itemandroid:iditemandroid:idandroid:id/progress clip android:clipOrientationvertical android:drawabledrawable/progress1 android:gravitybottom /clip /item /layer-list ?xmlversion1.0encodingutf-8?
layer-listxmlns:androidhttp://schemas.android.com/apk/res/androiditemandroid:idandroid:id/progressclipandroid:clipOrientationverticalandroid:drawabledrawable/progress1android:gravitybottom/clip/item
/layer-list 6.应用自定义的样式 [html] view plaincopyprint? Button android:idid/btStart android:layout_widthfill_parent android:layout_heightwrap_content android:layout_marginTop150dp android:text开始/ ProgressBar android:idid/pbPic styleandroid:style/Widget.ProgressBar.Horizontal android:layout_width50dp android:layout_height68dp android:backgrounddrawable/progress2 android:max100 android:progress0 android:progressDrawabledrawable/progress_vertical / !-- 在此属性上应用 -- TextView android:idid/txtProgress android:layout_widthwrap_content android:layout_heightwrap_content/ Buttonandroid:idid/btStartandroid:layout_widthfill_parentandroid:layout_heightwrap_contentandroid:layout_marginTop150dpandroid:text开始/ProgressBarandroid:idid/pbPicstyleandroid:style/Widget.ProgressBar.Horizontalandroid:layout_width50dpandroid:layout_height68dpandroid:backgrounddrawable/progress2android:max100android:progress0android:progressDrawabledrawable/progress_vertical / !-- 在此属性上应用 --TextViewandroid:idid/txtProgressandroid:layout_widthwrap_contentandroid:layout_heightwrap_content/ 7.点击按钮模拟进度滚动的效果 [java] view plaincopyprint? span stylecolor:#333333;public class ProgressActivity extends Activity { ProgressBar pb null; TextView txtProgress; Handler handler new Handler(); Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); System.out.println(主题 getTheme() ); pb (ProgressBar) findViewById(R.id.pbPic); Button btnStart (Button) findViewById(R.id.btStart);//按钮 txtProgress (TextView) findViewById(R.id.txtProgress);//显示进度 btnStart.setOnClickListener(new OnClickListener() {//按钮点击事件 publicvoid onClick(View v) { new Thread(new Runnable() {//创建并启动线程使用线程执行模拟的任务 publicvoid run() { for (inti 0; i 100; i) { //循环100遍 try { handler.post(new Runnable() { //更新界面的数据 publicvoid run() { pb.incrementProgressBy(1);//增加进度 txtProgress.setText(pb.getProgress() %);//显示完成的进度 } }); Thread.sleep(100); } catch (InterruptedException e) { } } } }).start(); } }); }/span } span stylecolor:#333333;public class ProgressActivity extends Activity { ProgressBar pb null;TextView txtProgress;Handler handler new Handler();Overridepublicvoid onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);System.out.println(主题 getTheme() );pb (ProgressBar) findViewById(R.id.pbPic);Button btnStart (Button) findViewById(R.id.btStart);//按钮txtProgress (TextView) findViewById(R.id.txtProgress);//显示进度btnStart.setOnClickListener(new OnClickListener() {//按钮点击事件publicvoid onClick(View v) {new Thread(new Runnable() {//创建并启动线程使用线程执行模拟的任务publicvoid run() {for (inti 0; i 100; i) { //循环100遍try {handler.post(new Runnable() { //更新界面的数据publicvoid run() {pb.incrementProgressBy(1);//增加进度txtProgress.setText(pb.getProgress() %);//显示完成的进度}});Thread.sleep(100);} catch (InterruptedException e) {}}}}).start();}});}/span
} 转载于:https://www.cnblogs.com/hudabing/p/4571113.html