android
java
按钮
定位
我的设备上运行的显示与预览不同。宽度和高度不固定,这是在 ConstraintLayout 中。问题出在按钮上;我希望它显示得低于两个 TextView。我应该对我的代码进行哪些更改? (我确实尝试用谷歌搜索它,并寻找答案,但除了按钮的“absoluteX,absoluteY”代码之外找不到任何相关内容)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<Button
android:id="@+id/button_button_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="order"
tools:layout_editor_absoluteY="100dp"
tools:layout_editor_absoluteX="4dp"/>
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="quantity"
android:textSize="16sp"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
app:layout_constraintBottom_toBottomOf="@id/quantity_text_view"
app:layout_constraintTop_toTopOf="@id/button_button_view"/>
最佳答案
预览看起来有所不同,因为您正在使用:
tools:layout_editor_absoluteY="100dp"
tools:layout_editor_absoluteX="4dp"
仅影响预览并且不会给设备供电。
尝试将按钮放在 TextView 下方
<Button
android:id="@+id/button_button_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/quantity_text_view"
app:layout_constraintStart_toStartOf="@+id/quantity_text_view"
.../>
关于java - 在我的设备上运行的应用程序与预览版不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60225629/