我是 Android Studio 的新手。我開始構建一個應用程式。這是我的 xml 檔案的代碼。我想不通問題!這是我得到的確切錯誤代碼。“ParseError at [row,col]:[60,1] 訊息:XML 檔案結構必須在同一物體內開始和結束。”
<?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"
android:background="#121212"
tools:context=".MainActivity"
>
<ImageView
android:id="@ id/imageView"
android:layout_width="844dp"
android:layout_height="1090dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/up_notch_adobespark" />
<ImageButton
android:id="@ id/imageButton4"
android:layout_width="50dp"
android:layout_height="54dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.005"
tools:srcCompat="@drawable/more_button" />
<ImageButton
android:id="@ id/imageButton7"
android:layout_width="59dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.997"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.004"
app:srcCompat="@drawable/help_icon" />
<TextView
android:id="@ id/textView"
android:layout_width="165dp"
android:layout_height="36dp"
android:fontFamily="@font/baloo_tamma"
android:text="Hi Josh."
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.158" />
uj5u.com熱心網友回復:
錯誤訊息是不言自明的。您ConstraintLayout在檔案的開頭打開了標簽,但從未關閉它。您需要在最后添加以下內容:
</androidx.constraintlayout.widget.ConstraintLayout>
uj5u.com熱心網友回復:
就像 broot 解釋的那樣…… XML 語法類似于 HTML,它有一個開始和結束標記,因此您需要關閉您打開的每個標簽,其中您的案例是約束布局。只需將此行添加到您的 xml 檔案的末尾
</androidx.constraintlayout.widget.ConstraintLayout>
另一個非常有用的建議是避免使用horizontal and vertical bias,我相信 padding(s) 和 margin(s) 足以幫助你設計你想要的布局
并嘗試使用寬度和高度 wrap_content or match parent為將使用的大多數手機進行詳細和正確的測量。因為如果您更改了正在使用的護身符,您會注意到測量結果會有所不同,因此最佳實踐是使用 wrap_content或match parent
uj5u.com熱心網友回復:
你錯過了關閉標簽 ConstraintLayout
</androidx.constraintlayout.widget.ConstraintLayout>
現在你的代碼將是
<?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"
android:background="#121212"
tools:context=".MainActivity"
>
<ImageView
android:id="@ id/imageView"
android:layout_width="844dp"
android:layout_height="1090dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/up_notch_adobespark" />
<ImageButton
android:id="@ id/imageButton4"
android:layout_width="50dp"
android:layout_height="54dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.005"
tools:srcCompat="@drawable/more_button" />
<ImageButton
android:id="@ id/imageButton7"
android:layout_width="59dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.997"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.004"
app:srcCompat="@drawable/help_icon" />
<TextView
android:id="@ id/textView"
android:layout_width="165dp"
android:layout_height="36dp"
android:fontFamily="@font/baloo_tamma"
android:text="Hi Josh."
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.158" />
</androidx.constraintlayout.widget.ConstraintLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/334731.html
