在我的 Android 應用程式中,我嘗試添加一個 TextView 來為我的某些活動添加標題。但是,它似乎不起作用,因為在我的所有活動中 TextViews 都不顯示。我是開發 Android 應用程式的新手,所以我可能在做一些根本錯誤的事情,但我嘗試添加不同的元素(按鈕、純文本等),它們都出現了,我只有 Textview 有問題.
這是我的代碼:
<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=".WishlistActivity">
<TextView
android:id="@ id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="173dp"
android:layout_marginTop="87dp"
android:layout_marginEnd="156dp"
android:layout_marginBottom="625dp"
android:text="Wishlist stuff"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>```
uj5u.com熱心網友回復:
<?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">
<TextView
android:id="@ id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="173dp"
android:layout_marginTop="87dp"
android:layout_marginEnd="156dp"
android:layout_marginBottom="625dp"
android:text="Wishlist stuff"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
輸出影像
代碼沒有錯誤,只是根據您的螢屏尺寸更正邊距。
uj5u.com熱心網友回復:
洗掉 Textview 內的邊距并嘗試
uj5u.com熱心網友回復:
您可能只是將 textview 拖放到 ContraintLayout 中并將其移動到特定位置。Android Studio 通過相應地調整邊距來移動視圖。然后你將它設定為 0dp,希望它會擴展,它通常會這樣做。之后您只是錯過了洗掉或調整邊距。
嘗試這個:
<TextView
android:id="@ id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Wishlist stuff"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
uj5u.com熱心網友回復:
當您運行應用程式或僅在 android studio 渲染時,Textview 是否不顯示?您還可以提供更多資訊,例如您在 style.xml 中使用的 App 主題以及依賴項部分中的材料組件版本。
可以幫助您解決問題的事情:
1 - 嘗試更新您的材料組件依賴項
2- 在 style.xml 中更改應用程式主題
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/368398.html
標籤:安卓 xml 安卓布局 android-xml
