Подтвердить что ты не робот

Пользовательский диапазон кнопок Android

У меня есть настраиваемый макет кнопки

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape>
            <gradient android:startColor="@color/pres1"
                android:endColor="@color/pres2" android:angle="270" />
            <stroke android:width="5dp" android:color="@color/stro3" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="20dp"
                android:right="10dp" android:bottom="20dp" />
        </shape>
    </item>
    <item android:state_focused="true">
        <shape>
            <gradient android:endColor="@color/focu1"
                android:startColor="@color/focu2" android:angle="270" />
            <stroke android:width="5dp" android:color="@color/stro2" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="20dp"
                android:right="10dp" android:bottom="20dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient android:endColor="@color/norm1"
                android:startColor="@color/norm2" android:angle="270" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="20dp"
                android:right="10dp" android:bottom="20dp" />
        </shape>
    </item>

</selector>

И для приведенного ниже

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/all_white">

    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello"
        android:textColor="@color/all_red" />

    <Button android:id="@+id/mq_categories" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Browse Quiz Categories"
        android:background="@drawable/custom_button" />
    <Button android:id="@+id/mq_random" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Enter Random Quiz"
        android:background="@drawable/custom_button" />

</LinearLayout>

создается следующий вывод

alt text

Мне нужно добавить некоторый запас между кнопками, Любая помощь оценивается..

4b9b3361

Ответ 1

Просто сделайте это так.

<Button android:id="@+id/mq_categories"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Browse Quiz Categories"
    android:background="@drawable/custom_button"
    android:layout_marginBottom="5dp"/>

Таким образом вы устанавливаете запас с 5 независимыми от плотности пикселей в нижней части первой кнопки.

Ответ 2

Вместо LinearLayout используйте RelativeLayout, чтобы поля можно было установить так, как вы можете. Приветствия

Ответ 3

У меня была та же проблема, и решение, похоже, не было. После того, как я попробовал пару вещей, помогло,

  • Определить пользовательский макет кнопки, как это сделано в вопросе
  • Внутри res > values > styles.xml файл добавьте новый стиль, как показано ниже,

    <style name="Widget.Button_Custom" parent="android:Widget">
        <item name="android:layout_margin">5dp</item>
        <item name="android:background">@drawable/button_custom</item>
    </style>
    
  • Используйте стиль в макете

<?xml version="1.0" encoding="utf-8"?> 
<Button android:id="@+id/mq_categories" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="
        android:background="@drawable/custom_button" 
        style="@style/Widget.Button_Custom"
/>

Это должно сделать это. Помимо поля, вы можете определить многие другие свойства в теге стиля. Надеюсь, что это поможет!