如何在按钮周围实现循环进度指示器?

时间:2012-08-23 12:27:36

标签: android android-layout android-progressbar

我已经尝试了很多方法来实现下面的例子,但是我不能让它普遍适用。

我已经完成了以下屏幕的构建。我已经对齐右中心和中心垂直。给予一定的余地。

enter image description here

我的问题是我必须为此添加onpressed状态,我需要添加一个循环进度,如下面的截图。

enter image description here

我不知道如何在那个特定的地方实施循环进展。我尝试从左中心垂直实现进度并给出一些余量并修复它。但是当我在大屏幕上安装时,校准会出错。所以我尝试从右中心垂直实现它,并为该圆圈提供边距。但即使这样也行不通。

请别人帮助我,如何解决这个问题:(

我对此感到震惊了一个多星期:(

修改 XML代码:

<ProgressBar
        android:id="@+id/ProgressBar01"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/circular_progress"
        android:layout_marginRight="185dp"
        android:progress="50" />

    <ImageButton
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@null"
        android:src="@drawable/tap_to_capture" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="@string/tap_to_cap"
        android:textSize="12sp"
        android:textColor="#006666"
        android:layout_marginRight="25dp"
        android:textAppearance="?android:attr/textAppearanceSmall" />

1 个答案:

答案 0 :(得分:1)

我使用了一个示例XML布局来获得与您正在寻找的类似效果。看一下这个截图和代码。

Screenshot of the layout

实现布局的XML粘贴在下面。显然你可以随心所欲地设计风格。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/RelativeLayoutLeftButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_play" />
    </RelativeLayout>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/RelativeLayoutLeftButton"
        android:text="Click Here"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#006666"
        android:textSize="12sp" />

</RelativeLayout>
相关问题