Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 缩放文本字段,两侧16dp_Android_Xml_Layout_Android Edittext_Textfield - Fatal编程技术网

Android 缩放文本字段,两侧16dp

Android 缩放文本字段,两侧16dp,android,xml,layout,android-edittext,textfield,Android,Xml,Layout,Android Edittext,Textfield,我试图在屏幕中间放置一个输入文本字段,右边和左边有16dP的边距。我应该在android中写些什么:布局和宽度?android:layout_width=“??” 谢谢你的帮助。我很感激 您可以将编辑文本放入一个

我试图在屏幕中间放置一个输入文本字段,右边和左边有16dP的边距。我应该在android中写些什么:布局和宽度?android:layout_width=“??”



谢谢你的帮助。我很感激

您可以将编辑文本放入一个
中,并在relativelayout中添加填充。然后将
relativelayout
android\u宽度设置为
match\u parent
。为此,请执行以下操作:

<RelativeLayout
android:layout_width="matchParent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<EditText
    android:id="@+id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="25dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:hint="YourText"
    android:ems="10" />
</RelativeLayout>

这取决于父视图组是什么。如果您的父视图组是一个相对视图,则应使用:

<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp" />
android:layout_gravity="center_horizontal"
而不是:

android:layout_centerHorizontal="true"

请看我的答案,它应该对你有用。是的,它有用。非常感谢!我很高兴能帮上忙!这是一个超级建议。“谢谢您的时间。”里卡普斯略有不同;您不需要将其包装在另一个布局中,但是的,相同的概念。:)
android:layout_centerHorizontal="true"