我在android studio上开发了一个应用程序,其中最小的SDK版本为21,目标是26, 除版本21,22之外的所有版本都运行良好。
我跑在运行棒棒糖的设备上,布局似乎很乱 看我的剧本
https://ibb.co/mGLhLo< - screenshoot
这是我对约束布局的依赖:
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
这是我的xml布局代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="@drawable/bg_tc_right"
tools:context="online.monita.monita.MainActivity">
<View
android:id="@+id/myRectangleView"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="@drawable/bg_rectangle_white_fade"
app:layout_constraintBottom_toBottomOf="@+id/login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/in_username" />
<TextView
android:id="@+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-smallcaps"
android:shadowColor="#fff"
android:shadowDx="5"
android:shadowDy="-5"
android:text="@string/app_name"
android:textColor="@android:color/black"
android:textSize="35sp"
app:layout_constraintBottom_toTopOf="@+id/myRectangleView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iv_logo_pp"
app:layout_constraintVertical_bias="0.06999999" />
<EditText
android:id="@+id/in_username"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/in_password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/myRectangleView"
app:layout_constraintVertical_bias="0.52" />
<EditText
android:id="@+id/in_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintBottom_toTopOf="@+id/login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/in_username" />
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="@drawable/btn_yellow"
android:elevation="14dp"
android:text="Login"
app:layout_constraintBottom_toTopOf="@+id/myRectangleView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/in_password" />
<ImageView
android:id="@+id/iv_logo_pp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
app:layout_constraintBottom_toTopOf="@+id/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo_pp" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/myRectangleView"
app:layout_constraintEnd_toEndOf="@+id/myRectangleView"
app:layout_constraintStart_toStartOf="@+id/myRectangleView"
app:layout_constraintTop_toTopOf="@+id/myRectangleView" />
</android.support.constraint.ConstraintLayout>
提前致谢,抱歉我的英文不好和我的第一篇文章。