我在任何 AndroidStudio 模擬器中都遇到了 ConstraintLayout 高度的問題。當我在多個設備上運行該應用程式時,我可以很好地看到所有布局渲染。但是,當我在模擬器中運行應用程式時,底部選單超出范圍。
我的activity_main.xml有一個帶有WebView 和BottomNavigationView 的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"
android:orientation="vertical"
tools:context=".MainActivity">
<WebView
android:id="@ id/main_webview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_action_bar"
app:elevation="16dp"
app:itemIconTint="@color/color_iconos_bottom_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/main_webview" />
</androidx.constraintlayout.widget.ConstraintLayout>
當我在模擬器中運行我的應用程式時,選單不在螢屏上。我可以看到選單的頂部,但圖示低于螢屏限制。當我點擊選單的那個小區域時,我可以導航。所以,總而言之,選單在那里,但超出了限制。
模擬器渲染圖
當我在設備中運行應用程式時,我可以看到完美匹配的選單。我下載了與我擁有的設備相同的型號和 SDK 版本的模擬器,但我仍然看到它是錯誤的。
所以,問題是 ConstraintLayout 高度大于模擬器螢屏的高度。你能給我任何解決這個問題的方法嗎?
uj5u.com熱心網友回復:
問題是你有沖突約束,你將WebView底部鏈接到頂部,Navigation將導航頂部鏈接到底部WebView。
洗掉Navigation底部的鏈接WebView。
uj5u.com熱心網友回復:
我將屬性添加android:layout_marginBottom="45dp"到BottomNavigationView元素,現在選單出現在模擬器中。但是在設備中,選單下方有一個黑色范圍。似乎 ConstraintLayout 的高度比模擬器螢屏高度大 45dp。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/388716.html
上一篇:消失在設計選項卡中
