سؤال

Is it possible to create a drawable (I guess a layer-list) splitted by two:

Half color (half left) be e.g. red, other right be green. But not use fixed dp values.

Think of like we can do with android-weigth for Linear and Relative layouts, but a drawable.

Is something like that possible only with XML code?

هل كانت مفيدة؟

المحلول

try this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="#0f0" />
        </shape>
    </item>
    <item>
        <clip>
            <shape>
                <solid android:color="#f00" />
            </shape>
        </clip>
    </item>
</layer-list>

make sure to call view.getBackground().setLevel(5000) in order to see half red half green output

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top