Android:视图之间的间距均匀,垂直对齐
我的布局有4个垂直对齐的编辑文本视图。但是在最后一个编辑文本之后有空的空格。我希望将这些视图均匀对齐,以便视图前后的间距b/w相同。 如何做到这一点Android:视图之间的间距均匀,垂直对齐,android,android-layout,Android,Android Layout,我的布局有4个垂直对齐的编辑文本视图。但是在最后一个编辑文本之后有空的空格。我希望将这些视图均匀对齐,以便视图前后的间距b/w相同。 如何做到这一点 --nehatha如果您使用的是xml,则在所有EditText中添加此标记 android:layoutMargin = "5dip" 在父布局中(我将假定其线性布局) 已更新 添加硬编码值不会损害您的代码,因为“dip”和“dp”都是适应不同屏幕分辨率的单元。如果屏幕分辨率改变,它对evn没有影响 检查一下这个 您可以将每个EditText包
--nehatha如果您使用的是xml,则在所有EditText中添加此标记
android:layoutMargin = "5dip"
在父布局中(我将假定其线性布局)
已更新
添加硬编码值不会损害您的代码,因为“dip”和“dp”都是适应不同屏幕分辨率的单元。如果屏幕分辨率改变,它对evn没有影响
检查一下这个 您可以将每个
EditText
包装成一个布局权重相等的FrameLayout
,并将这些框架布局的Gravity
设置为居中(或EditText
的layou Gravity
)
编辑:我的初始解决方案在顶部和底部留下的空间比编辑文本之间的空间要小。但这一个很好:只需在每个视图之间以及顶部和底部使用
layout\u weight=“1”
添加FrameLayout
:
Hi@ntc,layoutMarginBottom对我来说很有用,但是有没有什么智能方法可以避免这些硬编码的dip值,并根据屏幕分辨率动态对齐?是的,对我来说很好;但我必须检查不同分辨率的设备。@ngesh,类似于文卡特的问题,是否有一种方法可以平衡不同大小屏幕的间距(而不是分辨率)。我希望我的元素在大屏幕上扩展以填充空间(通过增加它们之间的间距),但在小屏幕上至少有一些最小间距。@emazm,你能解释一下在FrameLayout中包装视图的工作原理吗?
android:layoutHeight = "wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
></FrameLayout>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
></EditText>
<FrameLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</FrameLayout>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
></EditText>
<FrameLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</FrameLayout>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
></EditText>
<FrameLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</FrameLayout>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
></EditText>
<FrameLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</FrameLayout>
</LinearLayout>