我遇到了一个以前从未遇到过的重大问题。我做了我通常在约束条件下所做的工作。并非我的所有字段都可以在屏幕上显示。它显示可以在外接平板电脑上正常运行。以下是我的活动主体。我还以线性和相对布局运行它。我可以。任何帮助将不胜感激。
<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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBlack"
tools:context=".MainActivity">
<Spinner
android:id="@+id/spCompany"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="468dp"
android:background="@color/colorWhite"
android:gravity="center"
android:spinnerMode="dropdown"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rnumberText" />
<TextView
android:id="@+id/densityText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/strainerLabel"
app:layout_constraintTop_toBottomOf="@+id/spCompany" />
<TextView
android:id="@+id/strainerLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/strainer"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/strainerText"
app:layout_constraintTop_toBottomOf="@+id/spCompany" />
<TextView
android:id="@+id/strainerText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text=""
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/spRatio"
app:layout_constraintTop_toBottomOf="@+id/strainerLabel" />
<Spinner
android:id="@+id/spRatio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toTopOf="@+id/enterweightLabel"
app:layout_constraintTop_toBottomOf="@+id/strainerText" />
<TextView
android:id="@+id/rnumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/spCompany"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside" />
<TextView
android:id="@+id/catdensityText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:text=""
app:layout_constraintBottom_toBottomOf="@+id/spRatio"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spRatio" />
<TextView
android:id="@+id/enterweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/enter_weight"
android:textAlignment="center"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/weightInput"
app:layout_constraintTop_toBottomOf="@+id/spRatio" />
<EditText
android:id="@+id/weightInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:autofillHints="Enter Weight"
android:background="@color/colorWhite"
android:clickable="true"
android:ems="10"
android:focusable="true"
android:gravity="center"
android:imeOptions="actionDone"
android:importantForAutofill="yes"
android:inputType="numberDecimal"
android:singleLine="true"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalcatLabel"
app:layout_constraintTop_toBottomOf="@+id/enterweightLabel"
tools:targetApi="o" />
<TextView
android:id="@+id/totalcatLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/total_catalyst"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalcatText"
app:layout_constraintTop_toBottomOf="@+id/weightInput" />
<TextView
android:id="@+id/totalcatText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:clickable="false"
android:gravity="center"
android:text=""
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalweightLabel"
app:layout_constraintTop_toBottomOf="@+id/totalcatLabel" />
<TextView
android:id="@+id/totalweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/total_weight"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalweightText"
app:layout_constraintTop_toBottomOf="@+id/totalcatText" />
<TextView
android:id="@+id/totalweightText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center_horizontal|center_vertical"
android:text=""
android:textSize="60sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/calcButton"
app:layout_constraintTop_toBottomOf="@+id/totalweightLabel" />
<Button
android:id="@+id/calcButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="@string/calculate"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/clearButton"
app:layout_constraintTop_toBottomOf="@+id/totalweightText" />
<Button
android:id="@+id/clearButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="@string/Clear"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/calcButton" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
您可以将ConstraintLayout放在ScrollView中
答案 1 :(得分:0)
是的,您的内容占用的空间超过可用空间,然后视图会使设备溢出。使用ScrollView可以解决屏幕短的问题。
This如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
android:id="@+id/root">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBlack"
tools:context=".MainActivity">
<Spinner
android:id="@+id/spCompany"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="468dp"
android:background="@color/colorWhite"
android:gravity="center"
android:spinnerMode="dropdown"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rnumberText" />
<TextView
android:id="@+id/densityText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/strainerLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spCompany" />
<TextView
android:id="@+id/strainerLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/strainer"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/strainerText"
app:layout_constraintTop_toBottomOf="@+id/spCompany" />
<TextView
android:id="@+id/strainerText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text=""
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/spRatio"
app:layout_constraintTop_toBottomOf="@+id/strainerLabel" />
<Spinner
android:id="@+id/spRatio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toTopOf="@+id/enterweightLabel"
app:layout_constraintTop_toBottomOf="@+id/strainerText" />
<TextView
android:id="@+id/rnumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/spCompany"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside" />
<TextView
android:id="@+id/catdensityText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:text=""
app:layout_constraintBottom_toBottomOf="@+id/spRatio"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spRatio" />
<TextView
android:id="@+id/enterweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/enter_weight"
android:textAlignment="center"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/weightInput"
app:layout_constraintTop_toBottomOf="@+id/spRatio" />
<EditText
android:id="@+id/weightInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:autofillHints="Enter Weight"
android:background="@color/colorWhite"
android:clickable="true"
android:ems="10"
android:focusable="true"
android:gravity="center"
android:imeOptions="actionDone"
android:importantForAutofill="yes"
android:inputType="numberDecimal"
android:singleLine="true"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalcatLabel"
app:layout_constraintTop_toBottomOf="@+id/enterweightLabel"
tools:targetApi="o" />
<TextView
android:id="@+id/totalcatLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/total_catalyst"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalcatText"
app:layout_constraintTop_toBottomOf="@+id/weightInput" />
<TextView
android:id="@+id/totalcatText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@color/colorWhite"
android:clickable="false"
android:gravity="center"
android:text=""
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalweightLabel"
app:layout_constraintTop_toBottomOf="@+id/totalcatLabel" />
<TextView
android:id="@+id/totalweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center"
android:text="@string/total_weight"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/totalweightText"
app:layout_constraintTop_toBottomOf="@+id/totalcatText" />
<TextView
android:id="@+id/totalweightText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:gravity="center_horizontal|center_vertical"
android:text=""
android:textSize="60sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/calcButton"
app:layout_constraintTop_toBottomOf="@+id/totalweightLabel" />
<Button
android:id="@+id/calcButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="@string/calculate"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/clearButton"
app:layout_constraintTop_toBottomOf="@+id/totalweightText" />
<Button
android:id="@+id/clearButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="@string/Clear"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/calcButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>