android - 卡片 View 的最后一行未在所有设备中显示

标签 android android-cardview

我正在一个android应用程序中工作,在这个应用程序中我有cardview,我的问题是当我运行该应用程序时它工作正常但cardview的最后一行未正确显示。

我检查了几个模拟器设备,它在所有设备中显示相同。

请帮我解决这个问题。

cardview.xml

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="3dp"
    cardview:cardElevation="5dp"
    cardview:cardUseCompatPadding="true"
    cardview:cardCornerRadius="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/mReminder_Image_Id"
                android:layout_width="wrap_content"
                android:layout_height="80dp"
                android:scaleType="fitXY"
                android:background="#ffffff"/>
            <TextView
                android:id="@+id/mReminder_Text_Id"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textColor="#2d2d2d"
                android:textSize="13sp"
                android:text="Reminder texts"/>
        </LinearLayout>
</android.support.v7.widget.CardView>

fragment_reminders.xml

<LinearLayout 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=".Fragments.Reminders">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Reminders"
            android:textSize="20dp"
            android:textStyle="bold"
            android:textColor="@color/tab_background"
            android:layout_gravity="center" />
    </android.support.v7.widget.Toolbar>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/mRecyclerView_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>

</LinearLayout>

activity_main.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:id="@+id/Conslayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"

        android:animateLayoutChanges="true"
        android:layoutMode="opticalBounds"
        android:background="?android:attr/windowBackground"

        app:itemBackground="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation"
        app:itemIconTint="@color/color_selector"
        app:itemTextColor="@color/color_selector" />

</android.support.constraint.ConstraintLayout>

最佳答案

用此替换您的 Activity 主布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"

        android:animateLayoutChanges="true"
        android:background="?android:attr/windowBackground"
        android:layoutMode="opticalBounds"

        app:itemBackground="?android:attr/windowBackground"
        app:itemIconTint="@color/color_selector"
        app:itemTextColor="@color/color_selector"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</LinearLayout>

说明:

您的 BottomNavigationView 与您的 FrameLayout 重叠。我用 LinearLayout 而不是 ContraintLayout 包装了你的 View 来使用权重,只是给了 FrameLayout 权重 1,所以它占据了底部导航上方的可用空间。

关于android - 卡片 View 的最后一行未在所有设备中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50105718/

相关文章:

带有单选按钮的 Android 本地化错误?

android - CardView 上的透明背景 - Android

android - 如何通过单击卡片 View 中的按钮来填充回收器 View

java - 从巨大的字符串中按部分创建数组

android - KSOAP 的特殊字符

android - 所有 firebase 依赖项的版本都是相同的,应用程序仍然会在启动后立即崩溃

android - 在android中通过cardview创建 View

android - 需要将文本移到下一行

java - 从 Recyclerview 打开包含卡片的新 Activity

java - CardView 每个单独的卡之间不存在间距