如何修复我的android应用程序中的对齐问题



我创建了一个登录页面,其中包含:1个小图像,2个文本框,1个按钮但我希望它们在所有类型的设备中对齐,就像我在设备上尝试时一样,它看起来很好,但不适用于其他屏幕尺寸较大较小的设备

提前感谢

这是代码:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hardwareAccelerated="true"
android:background="@color/white"
tools:context=".MainActivity">
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:hardwareAccelerated="true" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
android:background="@color/blend"
android:contentDescription="@string/todo"
app:srcCompat="@drawable/imagelogo" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="58dp"
android:layout_marginBottom="294dp"
android:ems="10"
android:hint="@string/User_name"
android:inputType="text" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="147dp"
android:layout_marginBottom="227dp"
android:ems="10"
android:hint="@string/Pass_word"
android:inputType="textPassword" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="97dp"
android:layout_marginBottom="138dp"
android:ems="13"
android:background="@color/colorPrimary"
android:text="@string/login" />

以及输出:设计+蓝图

所以我想在每种类型的设备中把我所有的东西都放在同一个地方

将以下内容添加到您的项目级Gradle文件中:

compile 'com.intuit.sdp:sdp-android:1.0.5'

用法:在代码中,无论您在哪里指定尺寸,如10dp,都将其更改为@dimen/_10sdp

<ImageView
android:id="@+id/your_image"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
android:src="@drawable/logo"/>

这将使您的应用程序在不同的设备上看起来相同。

最新更新