Android 以编程方式更新水平进度条宽度(在水平滚动视图中)
我在scroll view中有一个进度条,我想通过编程方式修改宽度,但这似乎是不可能的,在xml中,我只有这样的进度条:Android 以编程方式更新水平进度条宽度(在水平滚动视图中),android,android-progressbar,horizontalscrollview,Android,Android Progressbar,Horizontalscrollview,我在scroll view中有一个进度条,我想通过编程方式修改宽度,但这似乎是不可能的,在xml中,我只有这样的进度条: <HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"> <ProgressBar android:id="@+id/progressbar" android:layo
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal" />
</HorizontalScrollView>
progressBar.getLayoutParams().width = 3000;
progressBar.invalidate();
我还尝试设置布局宽度,如下所示:
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal" />
</HorizontalScrollView>
progressBar.getLayoutParams().width = 3000;
progressBar.invalidate();
但发现它只适用于progressbar,而不适用于滚动视图
知道如何更新进度条宽度(在水平滚动视图中)吗?为什么滚动视图会影响进度条的宽度?
谢谢 您没有正确设置参数。试试这个:
HorizontalScrollView.LayoutParams params = (HorizontalScrollView.LayoutParams) progressBar.getLayoutParams();
params.width = 3000;
progressBar.setLayoutParams(params);
您没有正确设置参数。试试这个:
HorizontalScrollView.LayoutParams params = (HorizontalScrollView.LayoutParams) progressBar.getLayoutParams();
params.width = 3000;
progressBar.setLayoutParams(params);
以后,请不要删除一个问题,然后立即重新提问。@commonware,我这样做是因为原来的问题有了很大的变化,但得到了你的评论,以后不会这样做。谢谢“我这么做是因为原来的问题有了很大的变化”——这就是“编辑”链接的目的::-)以后,请不要删除一个问题,然后立即重新提问。@commonware,我这样做是因为原来的问题有了很大的变化,但得到了你的评论,以后不会这样做。谢谢“我这么做是因为原来的问题有了很大的变化”——这就是“编辑”链接的目的::-)