[英]My drag & drop is not working in 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 並拖動它(如果未安裝,將有下載)
設置 textview 的textview
然后嘗試通過拖動添加另一個視圖
<?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:layout_alignParentTop ="true"
android:layout_alignParentLeft="true"
android:text="@string/witaj_uzytkowniku" />
</RelativeLayout>
我認為您應該使用CoordinatorLayout而不是 Relativelayout。 如果您繼續使用 Relativelayout,則 go 文件無效並重新啟動您的 Android 工作室,如果這是與緩存相關的問題,然后解決它。
使用協調器布局工作。 RelativeLayout 更多的是編碼布局..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.