Which element do I need to modify to add padding between a drawable and its enclosed elements?

自古美人都是妖i 提交于 2019-12-11 08:52:41

问题


Based on what I learned here, I was able to add some "fences" around groupings of related widgets:

But, as you can see, the second/lower box is crowding the first radio button text. Which element do I need to modify to add some space? Do I need to add something to the box itself, which lives in the drawable folder and is defined like this:

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
    >
<stroke
    android:width="1dp"
    android:color="#f000"
    />
</shape>

...or to the inner LinearLayout, or to the radio button in question (or its enclosing RadioButtonGroup widget)? Here is that xml:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/box"
    android:orientation="vertical">

. . .

    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/radbtnBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/using_labels_black" />

. . .

    </RadioGroup>
</LinearLayout>

回答1:


Yes, you can add some padding, which will result in som inner space added:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <padding
        android:left="4dp"
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"
    />
    <stroke
        android:width="1dp"
        android:color="#f000"
    />
</shape>

Feel free to experiment different values other than 4dp (even different for top/bottom, left/right sides)



来源:https://stackoverflow.com/questions/23790506/which-element-do-i-need-to-modify-to-add-padding-between-a-drawable-and-its-encl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!