java - 在我的设备上运行的应用程序与预览版不同

标签 java android button android-constraintlayout preview

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/

相关文章:

ios - Swift 如何在 Webview 中打开链接?

java - 使用不同的基线来查询数据

java - 在线程对象上同步

android - 摆脱蓝线

android - MediaPlayer mOnPreparedListener 为空

c# - C# WPF 代码隐藏中的按钮处理程序

java - 如何向按钮添加方法以在 JavaFX 中的场景之间切换

java - 具有唯一性检查的 HashMap

java - X clicked/alt-F4 和 windowsclosing() 事件之间的事件

Android MultipartEntity POST 接收除 FileBody 之外的所有内容