来自 Android 的 BottomNavigationView 支持库遮挡视图
BottomNavigationView from Android Support Library Obstructing the Views
我在底栏中使用 BottomNavigationView,在 activity 中,我在 listView 中显示对象列表。但是我应用于 activity 的底栏阻碍了 listView 的最后一个元素..
从图中可以看出,最后一个列表元素被底部栏挡住了(最后一个元素的城市不可见)。
如何解决这个问题并在没有底栏干预的情况下正确显示列表元素。
这是 xml 代码:
<android.support.constraint.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="com.example.vendorapp.Promotion">
<RelativeLayout
android:id="@+id/mainrlot"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/cust_dtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Customer List"
android:textColor="#000000"
android:textSize="30sp" />
<ListView
android:id="@+id/cstmrListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:stackFromBottom="false"
android:transcriptMode="alwaysScroll"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="24dp"
tools:listitem="@layout/customer_list" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="end of result"
android:textSize="20sp"/>
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
您应该将 ID 为 cust_dtl
的布局置于 BottomNavigationView
之上,现在您的列表视图位于底部导航视图之后,这就是您看不到最后一行的原因
试试这个解决方案:
<RelativeLayout
android:id="@+id/mainrlot"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_alignParentBottom="true"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"/>
<LinearLayout
android:id="@+id/cust_dtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/navigation"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Customer List"
android:textColor="#000000"
android:textSize="30sp"/>
<ListView
android:id="@+id/cstmrListView"
app:layout_editor_absoluteX="8dp"
app:layout_editor_absoluteY="24dp"
app:listitem="@layout/customer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:stackFromBottom="false"
android:transcriptMode="alwaysScroll"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="end of result"
android:textSize="20sp"/>
</LinearLayout>
</RelativeLayout>
这样做。
<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"
tools:context="com.example.vendorapp.Promotion">
<LinearLayout
android:id="@+id/cust_dtl"
android:layout_above="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Customer List"
android:textColor="#000000"
android:textSize="30sp" />
<ListView
android:id="@+id/cstmrListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:stackFromBottom="false"
android:transcriptMode="alwaysScroll"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="24dp"
tools:listitem="@layout/customer_list" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="end of result"
android:textSize="20sp"/>
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:menu="@menu/navigation" />
</RelativeLayout>
我在底栏中使用 BottomNavigationView,在 activity 中,我在 listView 中显示对象列表。但是我应用于 activity 的底栏阻碍了 listView 的最后一个元素..
从图中可以看出,最后一个列表元素被底部栏挡住了(最后一个元素的城市不可见)。
如何解决这个问题并在没有底栏干预的情况下正确显示列表元素。 这是 xml 代码:
<android.support.constraint.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="com.example.vendorapp.Promotion">
<RelativeLayout
android:id="@+id/mainrlot"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/cust_dtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Customer List"
android:textColor="#000000"
android:textSize="30sp" />
<ListView
android:id="@+id/cstmrListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:stackFromBottom="false"
android:transcriptMode="alwaysScroll"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="24dp"
tools:listitem="@layout/customer_list" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="end of result"
android:textSize="20sp"/>
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
您应该将 ID 为 cust_dtl
的布局置于 BottomNavigationView
之上,现在您的列表视图位于底部导航视图之后,这就是您看不到最后一行的原因
试试这个解决方案:
<RelativeLayout
android:id="@+id/mainrlot"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_alignParentBottom="true"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"/>
<LinearLayout
android:id="@+id/cust_dtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/navigation"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Customer List"
android:textColor="#000000"
android:textSize="30sp"/>
<ListView
android:id="@+id/cstmrListView"
app:layout_editor_absoluteX="8dp"
app:layout_editor_absoluteY="24dp"
app:listitem="@layout/customer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:stackFromBottom="false"
android:transcriptMode="alwaysScroll"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="end of result"
android:textSize="20sp"/>
</LinearLayout>
</RelativeLayout>
这样做。
<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"
tools:context="com.example.vendorapp.Promotion">
<LinearLayout
android:id="@+id/cust_dtl"
android:layout_above="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Customer List"
android:textColor="#000000"
android:textSize="30sp" />
<ListView
android:id="@+id/cstmrListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:stackFromBottom="false"
android:transcriptMode="alwaysScroll"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="24dp"
tools:listitem="@layout/customer_list" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="end of result"
android:textSize="20sp"/>
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:menu="@menu/navigation" />
</RelativeLayout>