我有下面的按钮样式代码,但我无法在按钮之间进行填充。 我试过选择填充。它没用。 在我的活动xml代码下面,我用于实现
感谢您的帮助
选择器代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp" />
<corners android:radius="0dip" />
<stroke android:width="1dip" android:color="#2c2f34" />
<gradient android:angle="-90" android:endColor="#363c45" android:startColor="#090b0e" />
</shape></item>
<item android:state_focused="true"><shape android:shape="rectangle">
<padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp" />
<corners android:radius="0dip" />
<stroke android:width="1dip" android:color="#2c2f34" />
<solid android:color="#1d242c" />
</shape></item>
<item><shape android:shape="rectangle">
<padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp" />
<corners android:radius="0dip" />
<stroke android:width="1dip" android:color="#2c2f34" />
<gradient android:angle="-90" android:endColor="#1d242c" android:startColor="#545c67" />
</shape></item>
</selector>
styles.xml code
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="login_button_style" parent="@android:style/Widget.Button">
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:gravity">center</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">0.6</item>
<item name="android:background">@drawable/login_buttons_style</item>
<item name="android:padding">1dp</item>
</style>
</resources>
My activity xml code, here is the table 3X4, without padding between buttons
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/login_form_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:baselineAligned="false"
android:orientation="horizontal" >
<!-- left outer layout -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- middle layout -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<!-- middle top inner pincode-layout -->
<!-- middle center inner layout keypad buttons, top row -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/login_form_button1"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_1" />
<Button
android:id="@+id/login_form_button2"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_2" />
<Button
android:id="@+id/login_form_button3"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_3" />
</LinearLayout>
<!-- middle center inner layout keypad buttons, below-top row -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/login_form_button4"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_4" />
<Button
android:id="@+id/login_form_button5"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_5" />
<Button
android:id="@+id/login_form_button6"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_6" />
</LinearLayout>
<!-- middle center inner layout buttons, above bottom row -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/login_form_button7"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_7" />
<Button
android:id="@+id/login_form_button8"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_8" />
<Button
android:id="@+id/login_form_button9"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_9" />
</LinearLayout>
<!-- middle center inner layout buttons, bottom row -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/login_form_delete"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/delete" />
<Button
android:id="@+id/login_form_button0"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/key_0" />
<Button
android:id="@+id/login_form_login"
style="@style/login_button_style"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/login" />
</LinearLayout>
<!-- middle inner bottom layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
<!-- right outer layout -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
使用顶部和底部边距来显示按钮之间的间隙:
机器人:layout_marginTop =&#34; 5DP&#34;
机器人:layout_marginBottom =&#34; 5DP&#34;