Пользовательские круглые клипы ProgressBar для Android - PullRequest
0 голосов
/ 09 мая 2019

В моем приложении есть плавающий круговой таймер, который использует ProgressBar. Однако несколько пикселей края обрезаны в квадрат, как показано на этом изображении: problem (на некоторых устройствах это выглядит хуже)

Вот соответствующие макеты:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:alpha="0.85"
    xmlns:tools="http://schemas.android.com/tools">

    <ImageView
        android:id="@+id/imageView"
        android:layout_gravity="center"
        android:src="@drawable/circle_background"
        android:layout_width="50dp"
        android:layout_height="50dp"
        tools:ignore="ContentDescription" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_gravity="center"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:progressDrawable="@drawable/progress_circular"
        android:progress="100"/>

    <TextView
        android:id="@+id/timeTextView"
        android:layout_width="54dp"
        android:layout_height="54dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:textSize="12sp" />

</FrameLayout>

А progressDrawable:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:useLevel="true"
android:innerRadiusRatio="2.3"
android:shape="ring"
android:thickness="3.8sp" >
    <solid android:color="#ff205C" />
</shape>

Безрезультатно, я пробовал различные комбинации:

  • Установка FrameLayout на 54dp
  • Установка layout_width/height детей на fill_parent или 50dp или 54dp
  • Настройка margin на 2dp

Буду любить любые советы. Спасибо!

Ответы [ 2 ]

0 голосов
/ 09 мая 2019

Используйте приведенный ниже прогресс прорисовки

<?xml version="1.0" encoding="utf-8"?>                                   
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:innerRadiusRatio="2.5"
  android:shape="ring"
  android:thickness="2dp"
  android:useLevel="true">
<solid android:color="#ff205C" />                                
</shape>
0 голосов
/ 09 мая 2019

Попробуйте установить padding на FrameLayout и установить clipToPadding="false".

...