android 进度条的值是怎么来的
答案:2 悬赏:0
解决时间 2021-02-26 13:54
- 提问者网友:心裂
- 2021-02-26 09:23
android 进度条的值是怎么来的
最佳答案
- 二级知识专家网友:错过的是遗憾
- 2021-02-26 10:01
①首先在XML进行布局
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:max="100"
android:progress="50"
android:secondaryProgress="70" >
②代码中运用
private ProgressBar myProgressBar;
//定义ProgressBar
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);
//ProgressBar通过ID来从XML中获取
myProgressBar.incrementProgressBy(5);
//ProgressBar进度值增加5
myProgressBar.incrementProgressBy(-5);
//ProgressBar进度值减少5
myProgressBar.incrementSecondaryProgressBy(5);
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:max="100"
android:progress="50"
android:secondaryProgress="70" >
②代码中运用
private ProgressBar myProgressBar;
//定义ProgressBar
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);
//ProgressBar通过ID来从XML中获取
myProgressBar.incrementProgressBy(5);
//ProgressBar进度值增加5
myProgressBar.incrementProgressBy(-5);
//ProgressBar进度值减少5
myProgressBar.incrementSecondaryProgressBy(5);
全部回答
- 1楼网友:懂得ㄋ、沉默
- 2021-02-26 10:08
这个其实很简单吧,你在application
里就可以计算这个长度了,因为一旦运行程序,不考虑横竖屏切换,只考虑坚屏的话。屏幕宽高是不会变的。
displaymetrics metric = getresources().getdisplaymetrics();
imageutils.screen_width = metric.widthpixels < metric.heightpixels ? metric.widthpixels : metric.heightpixels;这个就是你屏幕的宽高。减去屏幕左右的10dp就是你要的进度条宽度。
public static int dp2px(context c, float dp)
{
if (c == null)
{
return 0;
}
float density = c.getresources().getdisplaymetrics().density;
return (int) (dp * density + 0.5f);
}
imageutils.progress_width = imageutils.screen_width - dp2px(context, 20);这样你就不用在adapter里面进行多次运算了
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯