java - 我的拖放在 Android Studio 中不起作用
问题描述
正如您在上图中看到的那样,当您拖动某些东西时,有“to RightOf=button”、“below=button”的对齐选项,但是当我拖动某些东西时,没有显示任何类似的东西。谁能帮我解决这个问题?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:id="@+id/text_witaj_uzytkowniku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/witaj_uzytkowniku" />
</RelativeLayout>
解决方案
老实说,我更喜欢使用 ConstraintLayout 作为根。我相信使用拖放工具会更容易。
使用它时,请确保所有对象彼此(或父对象)至少垂直连接一次,水平连接一次。这在代码中的外观:
<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">
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/textView9" />
</androidx.constraintlayout.widget.ConstraintLayout>
您还可以使用侧面板调整距离。
要使用布局,您只需在 Pallete 中键入 Constraint layout 并拖动它(如果未安装,将有下载)
推荐阅读
- numpy - 创建向量矩阵之间所有可能平方差的 Numpy 数组
- c# - 集合视图中所选项目的圆角
- javascript - React/JS/TS - 表格不会呈现行
- git - 如何在镜像/分叉的 git 存储库之上维护更改?
- python - 返回列表中引用索引的元素
- angular - Angular 9 *ngFor 循环跳过数组中的一些对象
- python - 需要帮助使用 pygame 实现合并排序的可视化工具
- r - 以万无一失的方式覆盖离散的 x 轴标签,以避免标签和数据不匹配
- azure - BlobTrigger 在部署时会导致 Azure Functions 应用崩溃
- ios - 如何导出具有透明背景(Alpha 通道)的视频