所以我的android studio预览看起来像这样: ScreenShot from android studio
但是当我导出应用并在手机上运行时,它看起来像这样: Screenshot from the actual phone
这是我的activity_main.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"
tools:context=".MainActivity">
<ImageView
android:id="@+id/backgr"
android:layout_width="789dp"
android:layout_height="778dp"
app:srcCompat="@color/colorAccent"
tools:layout_editor_absoluteX="2dp"
tools:layout_editor_absoluteY="0dp" />
<TextView
android:id="@+id/txt_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="360dp"
android:text="Welcome to Auth-Guard!"
android:textColor="@color/colorPrimary"
android:textSize="31sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="Connect"
android:textColor="@color/colorAccent"
tools:layout_editor_absoluteX="148dp"
tools:layout_editor_absoluteY="304dp"
tools:textColor="aaa" />
<Switch
android:id="@+id/swt_theme"
android:layout_width="126dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="Dark Theme"
android:textColor="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="539dp" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
设置按钮和其他视图的约束。
答案 1 :(得分:0)
正如Raj所说,你应该正确设置视图的约束。我认为你需要学习ConstrainLayout
。
以下是一些帮助:https://developer.android.com/training/constraint-layout/
和本教程:https://www.journaldev.com/13590/android-constraintlayout