android - 为什么我的卡片 View 被剪裁

标签 android android-xml android-cardview

我使用 CardView 作为列表行布局中的父项,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="125dp"
    android:orientation="vertical"
    android:padding="15dp">

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="4dp">

        <RelativeLayout
            android:id="@+id/relative_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">


            <RelativeLayout
                android:id="@+id/relative_img"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:padding="0dp">

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="82dp"
                    android:layout_height="82dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerInParent="true"
                    android:layout_centerVertical="true"
                    android:background="@drawable/universal_button_blue_background"
                    android:scaleType="centerCrop" />
            </RelativeLayout>



        </RelativeLayout>
    </android.support.v7.widget.CardView>

</LinearLayout>

在 XML 预览中一切都很好,我得到了高程和角点: enter image description here

但是在设备上,我的 View 似乎被剪裁了:

enter image description here

这是我的 ListView 定义:

<ListView
                android:id="@+id/listView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:cacheColorHint="#00000000"
                android:divider="@null"
                android:dividerHeight="0dp"
                android:listSelector="@android:color/transparent" />
        </RelativeLayout>

最佳答案

在您的LinearLayout中使用android:clipToPadding="false"来防止由于填充而剪裁子元素。

在此屏幕截图中,您可以看到 LinearLayout 中的两个卡片 View 未被剪裁 Two card views not clipped by padding

更多信息请访问the Android developer site

关于android - 为什么我的卡片 View 被剪裁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31653299/

相关文章:

java - Android onCreate 没有被调用?

android - 导航栏中的项目未显示

android - 改变卡片的背景 (Android cardView)

Android - 构建卡片列表

android react-native在谷歌审批过程中避免 "Background location access not declared"

android - 在我的 Android 应用程序中查询 InApp 购买

java - 我可以通过编程方式从字节数组安装 Android 应用程序吗?

android - Circle ProgressBar Android改变厚度等

android - 使用协调器布局时 SnackBar 显示高于特定高度

android - 如何使 CardView 具有可点击和可检查的效果,以及如何使其成为深色主题?