繁体   English   中英

如何准确实现以下进度条功能?

[英]How can I exactly implement below progressbar functionality?

见下图,它根据刷卡的数量显示进度条。 进度指示器

我该如何实施? 请指导我通过 Java 和 XML 的示例

我试过这个:

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/progress_bar"
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:indeterminateDrawable="@drawable/progress_bar_style"
    android:theme="@style/DayTheme.WhiteAccent" />

我建议您使用 Android Seekbar 来实现此功能。

只需使用以下代码隐藏搜索栏拇指

seekBar.getThumb().mutate().setAlpha(0);

https://developer.android.com/reference/android/widget/SeekBar

你唯一需要做的就是。

 <ProgressBar
    android:id="@+id/progressBar1"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:max="100"
    android:progressTint="#4d34ff"
    android:progressBackgroundTint="#4d34ff"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

试试看,让我们知道。

用这个

xml

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize">

    <ImageView
        android:id="@+id/iv_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:padding="@dimen/_10sdp"
        android:src="@drawable/close"
        android:visibility="invisible" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/_7sdp"
        android:layout_centerInParent="true"
        android:layout_toLeftOf="@+id/tv_monkey"
        android:layout_toRightOf="@+id/iv_close"
       >

        <ProgressBar
            android:id="@+id/progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_6sdp"
            android:layout_margin="1dp"
            android:indeterminate="false"
            android:indeterminateDuration="1"
            android:background="@drawable/progress_bar_background"
            android:progressDrawable="@drawable/curved_progress_bar" />

    </FrameLayout>

    <ImageView
        android:id="@+id/tv_monkey"
        android:layout_width="@dimen/_30sdp"
        android:layout_height="@dimen/_30sdp"
        android:layout_alignParentRight="true"
        android:layout_centerInParent="true"
        android:padding="@dimen/_5sdp"
        android:src="@drawable/monkey_off" />
    <!--   android:text="@string/monkey_off"-->


</RelativeLayout>

@drawable/progress_bar_background

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/c_e6eaeb"/>
    <corners android:radius="3dp" />
    <stroke android:color="@color/c_e6eaeb" android:width="1dp" />
</shape>

@drawable/curved_progress_bar

   <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="3dp" />
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="3dp" />
                <solid android:color="@color/green" />//change progress color hear
            </shape>
        </clip>
    </item>
</layer-list>

输出

对于cardview,您使用此swipeCardView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM