2012-09-13 168 views
6

Android的按键我有以下布局有左,右页边距

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

<Button 
    android:id="@+id/sign_in" 
    style="@style/ButtonText" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/custom_button_green" 
    android:text="@string/signin_via_email" 
    android:textSize="15sp" 
    android:typeface="sans" /> 

现在按钮我真的不想要适应整个宽度,而我需要的边距从左边10dp和右边10dp。我已经设置了填充和layout_marginLeft和右侧的属性,但他们不工作。任何帮助?

亲切的问候

+1

你可以发布你的ButtonText样式代码吗? –

+0

'android:layout_width =“wrap_content”'并相应地指定边距。 – neevek

回答

0

你好用户,

请不要使用 “FILL_PARENT” 的高度永远。请给出实际的图像高度和重量,然后把MarginLeft和Right。它会工作肯定。

+0

但我可以计算屏幕的宽度。我只是想在屏幕的左侧和右侧留出10dp的余量。这应该工作? – AndroidDev

14
<Button 
style="@style/ButtonText" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:id="@+id/btnOk" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="OK" /> 
+7

@ user365019:okey那么你也可以接受答案 – MAC

+0

如果你使用“android:layout_marginHorizo​​ntal =”10dp“,它也可以。注意layout_marginHorizo​​ntal只适用于API 26或更高版本! – Lotan

0

使用此布局也将增加保证金,以您的按钮按钮是否是你的根元素那么有没有办法从布局增加保证金,同时增加按钮,其他一些布局可以指定保证金/填充

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="10dip" 
android:paddingRight="10dip" > 
<Button 
    android:id="@+id/sign_in" 
    style="@style/ButtonText" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/custom_button_green" 
    android:text="@string/signin_via_email" 
    android:textSize="15sp" 
    android:typeface="sans" /> 
</LinearLayout> 
2

我加

android:padding="10dp" 

input.xml 

..它的工作!

(我使用SoftKeyboard源代码,也有同样的问题)

相关问题