在我的应用程序中,我使用了线性布局(linearlayout),其中包含3个EditText元素。现在我想增加EditText元素之间的空间(padding)。这是否可能?
可以通过在EditText元素之间添加android:padding属性来增加它们之间的空间。您可以尝试不同的值,以获得所需的间距效果。在我的应用程序中,我使用了线性布局(linearlayout),其中包含3个EditText元素。现在我想增加EditText元素之间的空间(padding)。这是否可能?
可以通过在EditText元素之间添加android:padding属性来增加它们之间的空间。您可以尝试不同的值,以获得所需的间距效果。你应该在xml文件中的EditText中按照下面的方式设置布局边距:
android:layout_marginLeft="5dp"
你可以针对marginTop、marginBottom、marginRight和marginLeft进行设置,具体取决于您的要求。您必须在布局元素上指定此选项,而不是在布局本身上指定。
padding和Margin的区别: Padding涉及视图内部的空间,而Margin是视图外部或两个视图之间的空间。
如果需要在任何一个方向上增加视图外部的空间,可以按照以上所述实现;如果需要在视图周围的所有侧面上增加空间,则可以使用下面的标记:
android:layout_margin="5dp"
5dp
是从哪里来的? - Yousha Aleayoub为了给字段之间留出空白,可以在四个方向上分配边距。
android:layout_margin="10dp"
您还可以使用以下内容来指定不同的方向:
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
int left = 6;
int top = 12;
int right = 6;
int bottom = 6;
TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
EditText edXY = new EditText(inventory.this);
edXY.setLayoutParams(params);
.setPadding()
。 - ConcernedHobbit