Удалить отступы из Drawable внутри LayerDrawable - PullRequest
0 голосов
/ 23 февраля 2019

Я занимаюсь этим уже пару часов и не могу программно изменить отступы для отрисовок «progress» и «primaryProgress».

Используемый мной ресурс Drawable xml приведен ниже.

<?xml version="1.0" encoding="utf-8"?>

<!--
  Progress Bar Drawable that is drawn vertically. This is basically a copy of
  progress_horizontal_material from the Android SDK's drawable, but modified
  to draw vertically instead of horizontally.
 -->

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape android:shape="rectangle"android:tint="?colorControlNormal">
            <corners android:radius="@dimen/vertical_progress_bar_corner_radius" />
            <size android:width="@dimen/vertical_progress_bar_width" />
            <solid android:color="@color/white_disabled_progress" />
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip android:clipOrientation="vertical" android:gravity="bottom">
            <shape android:shape="rectangle" android:tint="?colorControlActivated">
                <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" />
                <corners android:radius="@dimen/vertical_progress_bar_corner_radius" />
                <size android:width="@dimen/vertical_progress_bar_width" />
                <solid android:color="@color/white_disabled_progress" />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip android:clipOrientation="vertical" android:gravity="bottom">
            <shape android:shape="rectangle" android:tint="?colorControlActivated">
                <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" />
                <corners android:radius="@dimen/vertical_progress_bar_corner_radius" />
                <size android:width="@dimen/vertical_progress_bar_width" />
                <solid android:color="@android:color/white" />
            </shape>
        </clip>
    </item>
</layer-list>

1 Ответ

0 голосов
/ 23 февраля 2019

Ниндзя, которого я искал, вообще не использовал отступы ... он использовал вставки вместо отступов.Чтобы очистить «отступы», мне пришлось очистить вкладки с помощью java / kotlin ...

Как очистить вкладки (т. Е. Padding) с помощью java / Kotlin:

val layerDarawble = drawable.mutate() as LayerDrawable // Important or else all instances of this drawable used in the app will be changed!
layerDrawable.setLayerInset(1, 0, 0, 0, 0)
layerDrawable.setLayerInset(2, 0, 0, 0, 0)

ВотXML, который теперь использует Insets вместо Padding:

<?xml version="1.0" encoding="utf-8"?>

<!--
    Progress Bar Drawable that is drawn vertically. This is basically a copy of
    progress_horizontal_material from the Android SDK's drawable, but modified
    to draw vertically instead of horizontally.
-->

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape android:shape="rectangle" android:tint="?colorControlNormal">
            <corners android:radius="@dimen/vertical_progress_bar_corner_radius" />
            <size android:width="@dimen/vertical_progress_bar_width" />
            <solid android:color="@color/white_disabled_progress" />
        </shape>
    </item>

    <!--
        Note...insets are used instead of padding because I could not for the life of 
        me figure out how to clear the padding on this Drawable programmatically.
    -->
    <item android:id="@android:id/secondaryProgress"
          android:left="1dp"
          android:top="1dp"
          android:right="1dp"
          android:bottom="1dp">
        <clip android:clipOrientation="vertical" android:gravity="bottom">
            <shape android:shape="rectangle" android:tint="?colorControlActivated">
                <corners android:radius="@dimen/vertical_progress_bar_corner_radius"/>
                <size android:width="@dimen/vertical_progress_bar_width"/>
                <solid android:color="@color/white_disabled_progress"/>
            </shape>
        </clip>
    </item>

    <!--
        Note...insets are used instead of padding because I could not for the life of me figure out
    how to clear the padding on this Drawable programmatically.
    -->
    <item android:id="@android:id/progress"
          android:left="1dp"
          android:top="1dp"
          android:right="1dp"
          android:bottom="1dp">
        <clip android:clipOrientation="vertical" android:gravity="bottom">
            <shape android:shape="rectangle" android:tint="?colorControlActivated">
                <corners android:radius="@dimen/vertical_progress_bar_corner_radius"/>
                <size android:width="@dimen/vertical_progress_bar_width"/>
                <solid android:color="@android:color/white"/>
            </shape>
        </clip>
    </item>

</layer-list>

... Я знал, что мне понадобится какой-нибудь ниндзя.Почему ты проклинаешь меня, Android?: - |

...