In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
这篇文章主要介绍了Android ProgressBar怎么实现进度条效果的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Android ProgressBar怎么实现进度条效果文章都会有所收获,下面我们一起来看看吧。
具体效果如下
1.XML布局
2.myprogressbar布局
3.MainActivity
public class MainActivity extends AppCompatActivity { private ProgressBar progesss; private TextView progesssValue; private LinearLayout full; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progesss = (ProgressBar) findViewById(R.id.progesss1); progesssValue = (TextView) findViewById(R.id.progesss_value1); full = (LinearLayout) findViewById(R.id.full); initview(); } private void initview() { progesss.setProgress(66); progesssValue.setText(new StringBuffer().append(progesss.getProgress()).append("%")); setPosWay1();// ToastUtil.showToast("进度为66");// Toast.makeText(this,"进度为:--66",Toast.LENGTH_SHORT).show(); // full.setOnTouchListener(new View.OnTouchListener() {//// @Override// public boolean onTouch(View v, MotionEvent event) {// int w = getWindowManager().getDefaultDisplay().getWidth();// switch (event.getAction()) {// case MotionEvent.ACTION_DOWN:// x1 = (int) event.getRawX();// progesss.setProgress(100 * x1 / w);// setPos();// break;// case MotionEvent.ACTION_MOVE:// x2 = (int) event.getRawX();// dx = x2 - x1;// if (Math.abs(dx) > w / 100) { //改变条件 调整进度改变速度// x1 = x2; // 去掉已经用掉的距离, 去掉这句 运行看看会出现效果// progesss.setProgress(progesss.getProgress() + dx * 100 / w);// setPos();// }// break;// case MotionEvent.ACTION_UP:// break;// }// return true;// }// }); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { setPos(); } } private void setPosWay1() { progesssValue.post(new Runnable() { @Override public void run() { setPos(); } }); } /** * 设置进度显示在对应的位置 */ public void setPos() { int w = getWindowManager().getDefaultDisplay().getWidth(); Log.e("w=====", "" + w); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) progesssValue.getLayoutParams(); int pro = progesss.getProgress(); int tW = progesssValue.getWidth(); if (w * pro / 100 + tW * 0.3 > w) { params.leftMargin = (int) (w - tW * 1.1); } else if (w * pro / 100 < tW * 0.7) { params.leftMargin = 0; } else { params.leftMargin = (int) (w * pro / 100 - tW * 0.7); } progesssValue.setLayoutParams(params); }}关于"Android ProgressBar怎么实现进度条效果"这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对"Android ProgressBar怎么实现进度条效果"知识都有一定的了解,大家如果还想学习更多知识,欢迎关注行业资讯频道。
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.