Android 如何在所有设备都相同的两个视图之间留出空间
我对片段使用RelativeLayout,我使用marginTop将按钮彼此之间的间距相等,并在片段中心垂直对齐。我想知道一种方法,这样所有设备的间距都是一样的。谢谢Android 如何在所有设备都相同的两个视图之间留出空间,android,Android,我对片段使用RelativeLayout,我使用marginTop将按钮彼此之间的间距相等,并在片段中心垂直对齐。我想知道一种方法,这样所有设备的间距都是一样的。谢谢 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:alpha="0.6"
tools:context=".option"
>
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:id="@+id/shapes"
android:background="@drawable/shapes"/>
<Button
android:layout_height="30dp"
android:layout_width="30dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:id="@+id/color"
android:background="@drawable/color"
/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"
android:id="@+id/images1"
android:background="@drawable/images1"/>
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="160dp"
android:id="@+id/txt"
android:background="@drawable/txt"
/>
<Button
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="210dp"
android:background="@drawable/save"/>
</RelativeLayout>
正如您提到的,您正在使用RelativeLayout作为父级,下面是示例代码,请将此代码放入RelativeLayout中。 我根据问题创建了此代码,并在评论中进行了讨论。 您可以在下面提到的线性布局中添加所有按钮,使用给定的格式
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
>
<Button
android:layout_height="30dp"
android:layout_width="30dp"
android:id="@+id/color"
android:background="@drawable/color"
/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="50dp"
android:id="@+id/images1"
android:background="@drawable/images1"
/>
</LinearLayout>
您可以根据您的要求进行修改。
您也可以将其用于可伸缩dp。您是否在dp中指定了边距?请提及您的xml代码是的,但在dp中指定边距是否会使所有设备的边距相同?为什么这个问题被否决。至少我没有发现任何类似的问题。您想在页面中央同时显示这两个按钮吗?或者,请正确指定您的问题,或者您也可以添加一个简单的图像,即您尝试创建的视图类型。