【发布时间】:2019-06-22 17:58:11
【问题描述】:
我正在尝试开发一个简单的项目管理应用程序。问题在于应用程序屏幕的 xml 布局。应用程序屏幕在不同设备中的比例不是很好。由于空间不足,某些元素甚至隐藏在某些设备中。
我已经尝试过同时使用线性布局和相对布局。我一直对相对布局和线性布局父块的宽度和高度使用“Match_parent”属性。但仍然在某些屏幕尺寸下,某些元素没有显示,它们位于显示区域下方。
<RelativeLayout
android:id="@+id/layout1"
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:background="@color/white"
tools:context=".login"
android:paddingTop="20dp"
>
<ImageView
android:id="@+id/loginImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_logo"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="LOGIN"
android:textColor="@color/orange"
android:textSize="50sp"
android:layout_below="@id/loginImage"
/>
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/logintextbackground"
android:layout_centerHorizontal="true"
android:layout_below="@id/loginText"
android:hint="Username"
android:textColorHint="@color/lightOrange"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="@color/lightOrange"
android:maxLength="15"
/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/logintextbackground"
android:layout_centerHorizontal="true"
android:layout_below="@id/username"
android:hint="Password"
android:textColorHint="@color/lightOrange"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="@color/lightOrange"
android:inputType="textPassword"
android:maxLength="16"
/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/login_button"
android:layout_below="@id/password"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/orText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="or"
android:textSize="20dp"
android:textColor="@color/orange"
android:layout_below="@id/loginButton"
android:layout_centerHorizontal="true"
/>
<Button
android:id="@+id/signUpButtonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/signup"
android:layout_below="@id/loginButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
/>
【问题讨论】:
-
一些截图会更好地描述这种情况。此外,您的布局 xml 文件看起来不完整。
标签: android android-studio android-linearlayout android-relativelayout