【问题标题】:Setting a Circular ProgressBar as a Left Drawable to a TextView programatically以编程方式将圆形进度条设置为 TextView 的左可绘制对象
【发布时间】:2019-11-21 02:29:36
【问题描述】:

我有一个progressbar_text TextView:

<TextView  
 android:id="progressbar_text"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
/>

和一个 custom_animated_shape.xml 为:

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="270"
        android:toDegrees="270">
    <shape
        android:innerRadius="20dp"
        android:innerRadiusRatio="2.5"
        android:shape="ring"
        android:thickness="5dp"
        android:useLevel="true">

        <gradient
            android:angle="0"
            android:endColor="@color/foo_color"
            android:startColor="@color/foo_color"
            android:type="sweep"
            android:useLevel="false"/>
    </shape>
</animated-rotate>

设置为:

progressbar_text.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.custom_animated_shape, 0, 0, 0)

不会工作

有没有办法将 循环进度条设置为 Left DrawableTextView

【问题讨论】:

标签: android android-animation android-xml android-drawable android-progressbar


【解决方案1】:

试试下面的代码,你可以把你的textview和progressbar包裹在linearlayout里面。

 <LinearLayout
                android:id="@+id/progress_layout"
                android:layout_width="match_parent"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="5dp"
                android:layout_height="20dp">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:textColor="#000"
                    android:textSize="12sp"
                    android:gravity="center_vertical"
                    android:text="Progress bar at right."/>
                <ProgressBar
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    style="@android:style/Widget.ProgressBar.Small"
                    android:layout_marginRight="5dp" />
            </LinearLayout>

【讨论】:

    猜你喜欢
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多