为什么Android Studio Preview与实际应用相比如此混乱?尽管在各个方面都受到限制,但其中一种观点仍然飞到角落。
我的问题的第二部分/第三部分是:为什么在我的应用程序中,第二个分隔符“ divider2”与单元1名称的底部之间有很大的空白?而且,为什么单元2设置和第二个分频器之间会有很大的余量?那里以前有30像素的边距,但现在不存在,因此不应该存在。
更多诊断信息:如果同时从unit2SpecialMod和unit2ShieldsUps元素中删除app:layout_constraintHeight_max =“ 40dp”,则预览将看起来像实际的应用程序。
还有,第四部分,为什么在预览中尽管视图被扔到了角落,但边距实际上仍然是正确的,至少在删除此行之前,为什么它们会变得不正确,就像显示实际的应用程序一样,一旦删除这条线?
屏幕截图:
This is a screenshot of the actual app, and you can see the weird margins
这是有问题的xml文件,有点长:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.Icantbelievedefaultisexample.nistic.starcraft2unitcollider.UnitVUnit"
xmlns:app="http://schemas.android.com/apk/res-auto">
<include
android:id="@+id/activity_main_include"
layout="@layout/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/battlePreview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Battle Preview"
android:padding="4dp"
android:textAlignment="center"
android:textSize="19dp"
android:textStyle="italic|bold"
android:background="@color/deepPurple"
app:layout_constraintHeight_percent="0.05"
android:textColor="@color/white"
app:layout_constraintTop_toTopOf="parent"
/>
<ImageButton
android:id="@+id/iconButton1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:text="Unit 1"
android:background="@drawable/ic_zoom_in_black_24dp"
android:backgroundTint="@color/grayGreen"
app:layout_constraintTop_toBottomOf="@id/battlePreview"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintWidth_percent="0.1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHeight_max="60dp"
app:layout_constraintBottom_toTopOf="@id/iconButton2"
app:layout_constraintEnd_toStartOf="@id/instructions"
app:layout_constraintVertical_bias="0"
app:layout_constraintHorizontal_bias=".5"
app:layout_constraintWidth_max="60dp"/>
<TextView
android:id="@+id/instructions"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/text_view_corners"
android:gravity="center"
android:text=" Unit 1"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:maxWidth="315dp"
android:paddingStart="8dp"
android:paddingLeft="8dp"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/battlePreview"
app:layout_constraintWidth_percent=".73"
app:layout_constraintHeight_percent=".06" />
<TextView
android:id="@+id/Vs"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:background="@drawable/text_view_corners"
android:gravity="center_vertical"
android:padding="8dp"
android:text="Vs"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/unit1SpecialMod"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="70dp"
app:layout_constraintHorizontal_bias=".5"
app:layout_constraintVertical_bias=".5"
app:layout_constraintStart_toEndOf="@+id/instructions"
app:layout_constraintTop_toBottomOf="@id/battlePreview"
app:layout_constraintWidth_percent=".11"
app:layout_constraintWidth_max="70dp"/>
<ImageButton
android:id="@+id/iconButton2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="Unit 2"
android:background="@drawable/ic_zoom_in_black_24dp"
android:backgroundTint="@color/grayGreen"
app:layout_constraintTop_toBottomOf="@id/iconButton1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/instructions"
app:layout_constraintWidth_percent="0.1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHeight_max="60dp"
app:layout_constraintVertical_bias="0"
app:layout_constraintBottom_toTopOf="@id/divider1"
app:layout_constraintWidth_max="60dp"/>
<TextView
android:id="@+id/instructions2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/text_view_corners"
android:gravity="center"
android:text=" Unit 2"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="@color/white"
android:paddingStart="8dp"
android:paddingLeft="8dp"
app:layout_constraintBottom_toTopOf="@id/divider1"
app:layout_constraintEnd_toEndOf="@+id/activity_main_include"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="@+id/activity_main_include"
app:layout_constraintTop_toBottomOf="@+id/instructions"
app:layout_constraintHorizontal_bias=".5"
app:layout_constraintWidth_percent=".73"
app:layout_constraintHeight_percent=".06"
app:layout_constraintVertical_bias="0.0"/>
<View
android:id="@+id/divider1"
style="@style/Divider"
android:layout_marginTop="8dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginRight="4dp"
android:layout_marginEnd="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/instructions2"
app:layout_constraintBottom_toTopOf="@id/unit1RaceFilter"/>
<TextView
android:id="@+id/unit1RaceFilter"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="------ Unit 1 Settings ------"
android:textAlignment="center"
android:textColor="@color/grayGreen"
android:textSize="16sp"
android:textStyle="bold|italic"
app:layout_constraintHeight_percent=".03"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider1"
app:layout_constraintBottom_toTopOf="@id/unit1Group"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintWidth_max="240dp"
app:layout_constraintWidth_percent=".5" />
<Spinner
android:id="@+id/unit1SpecialMod"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent=".055"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider1"
app:layout_constraintWidth_percent=".35"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintWidth_max="240dp"
app:layout_constraintHeight_max="40dp"/>
<RadioGroup
android:id="@+id/unit1Group"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/unit1RaceFilter"
app:layout_constraintWidth_percent=".62"
app:layout_constraintHeight_percent=".055"
app:layout_constraintHeight_max="40dp">
<RadioButton
android:id="@+id/Protoss"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:textSize="14sp"
android:buttonTint="@color/deepPurple"
android:gravity="center_vertical"
android:text="Protoss" />
<RadioButton
android:id="@+id/Terran"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:textSize="14sp"
android:gravity="center_vertical"
android:buttonTint="@color/deepPurple"
android:text="Terran" />
<RadioButton
android:id="@+id/Zerg"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:textSize="14sp"
android:gravity="center_vertical"
android:buttonTint="@color/deepPurple"
android:text="Zerg" />
</RadioGroup>
<Spinner
android:id="@+id/unit1ShieldsUps"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/unit1SpecialMod"
app:layout_constraintWidth_max="240dp"
app:layout_constraintHeight_max="40dp"
app:layout_constraintWidth_percent=".35" />
<Spinner
android:id="@+id/unit1Name"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintEnd_toStartOf="@+id/unit1AttackUps"
app:layout_constraintHeight_max="40dp"
app:layout_constraintHeight_percent=".055"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/unit1ShieldsUps"
app:layout_constraintWidth_max="350dp"
app:layout_constraintWidth_percent=".5" />
<Spinner
android:id="@+id/unit1AttackUps"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintWidth_max="120dp"
app:layout_constraintHeight_max="40dp"
app:layout_constraintBottom_toTopOf="@id/divider2"
app:layout_constraintEnd_toStartOf="@+id/unit1ArmorUps"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintTop_toBottomOf="@+id/unit1ShieldsUps"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintWidth_percent=".20" />
<Spinner
android:id="@+id/unit1ArmorUps"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintBottom_toTopOf="@id/divider2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="40dp"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintTop_toBottomOf="@+id/unit1ShieldsUps"
app:layout_constraintWidth_max="120dp"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintWidth_percent=".20" />
<View
android:id="@+id/divider2"
style="@style/Divider"
android:layout_marginTop="12dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginRight="4dp"
android:layout_marginEnd="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/unit1Name"
app:layout_constraintBottom_toTopOf="@id/unit2RaceFilter"/>
<TextView
android:id="@+id/unit2RaceFilter"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="------ Unit 2 Settings ------"
android:textAlignment="center"
android:textColor="@color/grayGreen"
android:textSize="16sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toTopOf="@id/unit2Name"
app:layout_constraintHeight_percent=".03"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider2"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintWidth_max="240dp"
app:layout_constraintWidth_percent=".5" />
<Spinner
android:id="@+id/unit2SpecialMod"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent=".055"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider2"
app:layout_constraintWidth_percent=".35"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintWidth_max="240dp"
app:layout_constraintHeight_max="40dp"
/>
<RadioGroup
android:id="@+id/unit2Group"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/unit2Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="40dp"
app:layout_constraintHeight_percent=".055"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/unit2RaceFilter"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintWidth_percent=".62"
app:layout_constraintVertical_bias="0.0">
<RadioButton
android:id="@+id/protoss"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:buttonTint="@color/deepPurple"
android:text="Protoss"
android:textSize="14sp" />
<RadioButton
android:id="@+id/terran"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:buttonTint="@color/deepPurple"
android:text="Terran"
android:textSize="14sp" />
<RadioButton
android:id="@+id/zerg"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:buttonTint="@color/deepPurple"
android:text="Zerg"
android:textSize="14sp" />
</RadioGroup>
<Spinner
android:id="@+id/unit2ShieldsUps"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintWidth_max="240dp"
app:layout_constraintHeight_max="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintTop_toBottomOf="@id/unit2SpecialMod"
app:layout_constraintWidth_percent=".35" />
<Spinner
android:id="@+id/unit2Name"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintEnd_toStartOf="@id/unit2AttackUps"
app:layout_constraintHeight_max="40dp"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/unit2ShieldsUps"
app:layout_constraintWidth_max="350dp"
app:layout_constraintWidth_percent=".5" />
<Spinner
android:id="@+id/unit2AttackUps"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintBottom_toTopOf="@+id/calculate"
app:layout_constraintEnd_toStartOf="@+id/unit2ArmorUps"
app:layout_constraintHeight_max="40dp"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintTop_toBottomOf="@+id/unit2ShieldsUps"
app:layout_constraintWidth_max="120dp"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintWidth_percent=".20" />
<Spinner
android:id="@+id/unit2ArmorUps"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/gradient_spinner"
app:layout_constraintBottom_toTopOf="@+id/calculate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="40dp"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintTop_toBottomOf="@+id/unit2ShieldsUps"
app:layout_constraintWidth_max="120dp"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintWidth_percent=".20" />
<Button
android:id="@+id/calculate"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/button_background"
android:gravity="center"
android:text="Collide Units"
android:textAllCaps="false"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@+id/resultsView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="80dp"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/unit2Name"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintWidth_max="500dp"
app:layout_constraintWidth_percent="0.5"
app:layout_constraintHorizontal_bias="0.0"/>
<Button
android:id="@+id/clear"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/button_background"
android:gravity="center"
android:text="Clear"
android:textAllCaps="false"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@id/home"
app:layout_constraintHeight_max="80dp"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintTop_toBottomOf="@id/unit2AttackUps"
app:layout_constraintWidth_max="120dp"
app:layout_constraintWidth_percent=".20" />
<Button
android:id="@+id/home"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/button_background"
android:text="Home"
android:textAllCaps="false"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="80dp"
app:layout_constraintHeight_percent="0.055"
app:layout_constraintTop_toBottomOf="@+id/unit2ArmorUps"
app:layout_constraintWidth_max="120dp"
app:layout_constraintWidth_percent=".20" />
<TextView
android:id="@+id/resultsView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="68dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:text="-------------------- R E S U L T S --------------------"
android:textAlignment="center"
android:textSize="15sp"
android:scrollbars="vertical"
android:scrollbarStyle="outsideInset"
android:fadeScrollbars="false"
android:scrollbarSize="6dp"
android:textColor="@color/deepPurple"
android:background="@drawable/textview_basic_border"
app:layout_constraintBottom_toBottomOf="@+id/activity_main_include"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.50"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/calculate"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHeight_max="400dp"
app:layout_constraintWidth_max="1200dp"
app:layout_constraintWidth_percent=".96"
app:layout_constraintHeight_min="60dp"/>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
我刚刚解决了这个问题,答案是....从除法器2中删除“ app:layout_constraintBottom_toTopOf =“ @ id / unit2RaceFilter”,因为unit2RaceFilter已经对除法器2施加了约束。即使无法直接键入,也无法被Android Studio发现。