Android 缩放文本字段,两侧16dp
我试图在屏幕中间放置一个输入文本字段,右边和左边有16dP的边距。我应该在android中写些什么:布局和宽度?android:layout_width=“??”Android 缩放文本字段,两侧16dp,android,xml,layout,android-edittext,textfield,Android,Xml,Layout,Android Edittext,Textfield,我试图在屏幕中间放置一个输入文本字段,右边和左边有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"