android-progressbar 相关问题

Android的ProgressBar小部件向用户显示可视化的工作进度指示。确定的进度条显示操作进度的程度。一个不确定的进度条只显示工作正在完成。

以编程方式更新水平进度条宽度(在水平滚动视图中)

我在滚动视图中有一个进度条,我想以编程方式修改宽度,但看起来这是不可能的,在xml中我只有这样的进度条: 我在滚动视图中有一个进度条,我想以编程方式修改宽度,但看起来这是不可能的,在 xml 中我只有这样的进度条: <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 progressBar = (ProgressBar) findViewById(R.id.progressbar); progressBar.setMinimumWidth(3000); progressBar.invalidate(); // tried called invalidate although setMinimumWidth called requestLayout, not help 我还尝试设置布局宽度,如下所示: progressBar.getLayoutParams().width = 3000; progressBar.invalidate(); 但发现它仅适用于进度条,不适用于滚动视图...... 如何更新进度条宽度(在水平滚动视图中)?为什么滚动视图会缺陷进度条宽度? 您没有以正确的方式设置参数。试试这个: HorizontalScrollView.LayoutParams params = (HorizontalScrollView.LayoutParams) progressBar.getLayoutParams(); params.width = 3000; progressBar.setLayoutParams(params);

回答 1 投票 0

如何在 Jetpack Compose 中使用按钮自定义进度条?

我正在尝试在 Jetpack Compose 中做这样的自定义进度条。 当我向右和向左滑动用户按钮时,它会以 0.25 的值增加和减少。第一个值将是...

回答 0 投票 0

如何在 Android drawable 中为环形制作圆角

我有一个自定义进度条,如下所示: 这是我用来创建它的 .xml 代码: background_drawable.xml 我有一个自定义进度条,看起来像这样: 这是我用来创建它的 .xml 代码: background_drawable.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="@dimen/progress_bar_radial_inner_radius" android:thickness="@dimen/progress_bar_radial_thickness" android:shape="ring" android:useLevel="false" > <solid android:color="@color/main_color_alpha"/> </shape> progress_drawable.xml <?xml version="1.0" encoding="UTF-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="270" android:toDegrees="270"> <shape android:innerRadius="@dimen/progress_bar_radial_inner_radius" android:thickness="@dimen/progress_bar_radial_thickness" android:shape="ring" > <solid android:color="@color/main_color"/> </shape> </rotate> 我想要得到的是我用来显示进度的圆环的圆角。看起来像这样的东西: 有人知道如何实现吗? 我能够使用图层列表并在线条的每一侧添加一个点来实现这一点。第一个将卡在顶部,而第二个将跟随进度,因为在旋转元素中添加了插图。不过,您必须根据进度条布局的大小对其进行调整。我的是 250dp x 250dp。 progress_drawable.xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <rotate android:fromDegrees="270" android:toDegrees="270"> <shape android:innerRadiusRatio="2.55" android:shape="ring" android:thickness="15dp" android:useLevel="true"> <solid android:color="@color/main_color" /> </shape> </rotate> </item> <item android:bottom="211dp"> <shape android:innerRadiusRatio="1000" android:shape="ring" android:thickness="7dp" android:useLevel="false"> <solid android:color="@color/main_color" /> </shape> </item> <item> <rotate> <inset android:insetBottom="211dp"> <shape android:innerRadiusRatio="1000" android:shape="ring" android:thickness="7dp" android:useLevel="false"> <solid android:color="@color/main_color" /> </shape> </inset> </rotate> </item> </layer-list> 好吧,我之前搜索了很多。 我找到的唯一解决方案是 GitHub 上的库检查here 通读这段代码希望这对你有帮助 >ProgressBarActivity.java public class ProgressBarActivity extends AppCompatActivity { private TextView txtProgress; private ProgressBar progressBar; private int pStatus = 0; private Handler handler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_progress); txtProgress = (TextView) findViewById(R.id.txtProgress); progressBar = (ProgressBar) findViewById(R.id.progressBar); new Thread(new Runnable() { @Override public void run() { while (pStatus <= 100) { handler.post(new Runnable() { @Override public void run() { progressBar.setProgress(pStatus); txtProgress.setText(pStatus + " %"); } }); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } pStatus++; } } }).start(); } } > activity_progress.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.placio.android.custom_progressbar_circular.MainActivity" > <RelativeLayout android:layout_width="wrap_content" android:layout_centerInParent="true" android:layout_height="wrap_content"> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="250dp" android:layout_height="250dp" android:layout_centerInParent="true" android:indeterminate="false" android:max="100" android:progress="0" android:progressDrawable="@drawable/progress_drawable" android:secondaryProgress="0" /> <TextView android:id="@+id/txtProgress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/progressBar" android:layout_centerInParent="true" android:textAppearance="?android:attr/textAppearanceSmall" /> </RelativeLayout> </RelativeLayout> > progress_drawable.xml <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="-90" android:pivotX="50%" android:pivotY="50%" android:toDegrees="270" > 好的,我发现做我想做的最简单的方法是在画布上绘制进度弧而不是使用 progress_drawable.xml。 这是我的代码,以防有人遇到类似问题。 class RadialProgressBar : ProgressBar { private val thickness = 28f private val halfThickness = thickness / 2 private val startAngle = 270f private var boundsF: RectF? = null private lateinit var paint: Paint constructor(context: Context?) : super(context) { init() } constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { init() } constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { init() } private fun init() { paint = Paint() paint.isAntiAlias = true paint.style = Paint.Style.STROKE paint.strokeWidth = thickness paint.strokeCap = Paint.Cap.ROUND paint.color = ContextCompat.getColor(context, R.color.main_color) progressDrawable = null } override fun draw(canvas: Canvas?) { super.draw(canvas) if (boundsF == null) { boundsF = RectF(background.bounds) boundsF?.inset(halfThickness, halfThickness) } canvas?.drawArc(boundsF, startAngle, progress * 3.60f, false, paint) } } Вы можете использовать данный пример https://github.com/lopspower/CircularProgressBar, тут полностью описано, как можно решиту пример ваш Добавляете это в build.gradle: implementation 'com.mikhaellopez:circularprogressbar:3.1.0' XML для решения моей проблемы: <com.mikhaellopez.circularprogressbar.CircularProgressBar android:id="@+id/progress_bar_Running" android:layout_width="260dp" android:layout_height="260dp" app:cpb_background_progressbar_color="#4100A550" app:cpb_background_progressbar_width="10dp" app:cpb_progressbar_color="#00a550" app:cpb_progressbar_width="10dp" app:cpb_progress="60" app:cpb_progress_max="100" app:cpb_progress_direction="to_right" app:cpb_round_border="true" android:layout_marginLeft="70dp" android:layout_marginTop="40dp"/> Вот так выглядит у меня в программе:

回答 5 投票 0

如何使用 Jetpack Compose 制作垂直进度指示器?

只是不知道如何在 Jetpack Compose 中制作提供的图片中的指示器。 尝试使用 LinearProgressIndicator 但据我所知,遗憾的是没有办法让它垂直。

回答 1 投票 0

更改 CircularProgressIndicator 宽度或高度未应用

我想使用材料库中的 CircularProgressIndicator 宽度自定义大小,但是当我为视图设置任何宽度或高度时,只是视图本身改变而不是它里面的圆圈。 我想要什么

回答 2 投票 0

如何使用 arthenica.ffmpegkit 获取压缩进度百分比?

我在 Kotlin 中有一个应用程序可以使用 arthenica.ffmpegkit 压缩视频。我在文档中进行了搜索,但我不清楚如何以百分比形式获得压缩进度,即使它是 pos ...

回答 0 投票 0

安卓:改变进度条的可见性不起作用

我的布局中有一个使用数据绑定的进度条。

回答 1 投票 0

如何确定进度条已停止

我知道要 "停止 "进度条,需要把它的可见性设置为View.GONE。但是......这真的能让它停止吗?后台有一个动画,可以使视图产生动画。那是...

回答 1 投票 1

在没有网络连接的情况下显示刷新页面按钮

我有一个需要连接互联网的活动,我放了一个加载页面的进度条,但是当用户没有连接互联网的时候,进度条始终是可见的,就像 ...

回答 1 投票 1

在进度条可见的情况下,使用户交互不活跃。

在一个对话框片段中,当我使用一个进度条(不是进度对话框)时,我想完成一个任务,然后允许用户交互。可以通过使用setCancelable(false)来实现进度条,...

回答 1 投票 0

Android Media会话的播放状态不会通知位置更新

Android媒体会话的播放状态在暂停播放后不会通知位置更新。在其余的播放过程中,GetPlaybackPosition()返回在“暂停”处设置的相同位置。有什么线索吗?谢谢。

回答 1 投票 0

将垂直线添加到ProgressBar

我有一个ProgressBar,效果很好。我使用了以下布局:

回答 1 投票 0

如何在Android中使用水平的“物料进度指示器”?

我已经使用“ android.material.progressindicator”来显示水平视图中的进度,但是我听不到我的XML

回答 1 投票 1

Android多个Progressbar实例未正确更新

我有一个带有进度条的CustomView。自定义视图具有进度栏,标题和文本进度为“ 1/5”。我在多个地方使用了CustomView(ProgressBadgeWidget),包括...

回答 1 投票 0

进度栏加载未显示来自服务器的响应?

我正在开发新闻应用程序,但TopHeadlinesFragment加载进度栏未显示服务器的响应,我想知道我在哪里弄错了,为了显示来自...的响应,我必须要做的事情]]

回答 1 投票 0

如何在进度栏中添加下载按钮或自定义布局?

我想创建一个自定义进度条,以在其中心显示带有图标和textview的下载进度,如下所示:有库和一些示例,但仅内部具有textview ...

回答 2 投票 0

如何显示进度条,直到在Android中打开Webview

活动从意图开始后,需要显示一个ProgressBar。一旦显示WebView,则需要隐藏ProgressBar。但是无法在屏幕上显示ProgressBar。以下是我的xml,&...

回答 1 投票 0

ProgressDialog旋转圈

我想像这样实现ProgressDialog,而没有其他框架。:但是我得到了这个。我该如何改变?这是我的ProgressDialog代码。预先感谢私人...

回答 4 投票 55

如何更改Android进度条的厚度

这应该是一种非常容易自定义的样式...我想要一个水平的进度条,它稍显粗细(或者我可以自定义厚度),并且如果我这样做,则颜色与应用程序的颜色匹配 ] > 有很多方法可以满足您的需求: 1-使用XML文件中的android:scaleY="8" 或来自代码 mProgressBar.setScaleY(3f); 2-style="@android:style/Widget.ProgressBar.Horizontal"这将使您具有水平进度条,因此您可以继承样式并按如下方式对其进行编辑: <style name="CustomProgressBarHorizontal" parent="android:Widget.ProgressBar.Horizontal"> <item name="android:progressDrawable">@drawable/custom_progress_bar_horizontal</item> <item name="android:minHeight">10dp</item> <item name="android:maxHeight">20dp</item> </style>

回答 1 投票 0

当用户单击后退箭头图像按钮时,进度条指示器在本机响应中不会减少

我想实现此功能,当用户单击后退箭头图像按钮时,进度条指示器将减少,它将在轮播中显示先前的问题。我正在使用'react -...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.