android - CardView 不显示阴影高程

标签 android xml android-cardview

我正在使用卡片 View ,但问题是我的卡片 View 没有显示任何高度或阴影。我已经尝试过 stackoverflow 答案中建议的一些方法,就像我尝试过使用 elevation 和 shadow 属性一样。我也尝试过使用 card_view:cardUseCompatPadding="true",但没有成功。这是我的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    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="wrap_content"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:layout_marginTop="6dp"
    android:layout_marginBottom="6dp"
    app:cardBackgroundColor="#FAFBFD"
    app:cardElevation="5dp">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/post_profile_image"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@mipmap/ic_launcher"
                android:layout_marginLeft="12dp"
                android:layout_marginTop="12dp"/>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/post_profile_image"
                android:layout_marginLeft="12dp"
                android:orientation="vertical"
                android:layout_marginTop="16dp">

                <TextView
                    android:id="@+id/post_username"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Name"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#000000"/>

                <TextView
                    android:id="@+id/post_time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:text="Time"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/grayColor"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true">

                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@android:drawable/ic_delete"
                    android:id="@+id/post_delete_btn"
                    android:visibility="invisible"/>

            </LinearLayout>

        </RelativeLayout>

        <ImageView
            android:id="@+id/post_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="12dp"
            android:adjustViewBounds="true"
            android:background="#00ffffff"
            android:src="@drawable/add_btn"
            android:visibility="gone"/>

        <TextView
            android:id="@+id/post_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:layout_marginLeft="12dp"
            android:text="Text about Posting...."
            android:textAppearance="?android:attr/textAppearanceMedium"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:layout_marginBottom="8dp">

            <ImageButton
                android:id="@+id/like_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="12dp"
                android:background="#00ffffff"
                android:src="@drawable/grey_like_bt"/>

            <TextView
                android:id="@+id/post_like_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:layout_marginTop="8dp"
                android:text="0 Likes"
                android:textColor="#2196F3"/>

            <ImageButton
                android:id="@+id/comment_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="32dp"
                android:background="#00ffffff"
                android:src="@drawable/comment_btn_gray"/>

            <TextView
                android:id="@+id/post_comment_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:layout_marginTop="8dp"
                android:text="0 Comments"
                android:textColor="#2196F3"/>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@android:drawable/ic_menu_edit"
                    android:visibility="invisible"
                    android:id="@+id/post_edit_btn"
                    android:layout_alignParentRight="true"/>

            </RelativeLayout>

        </LinearLayout>

    </LinearLayout>

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

不知道为什么它没有显示任何高度和阴影

最佳答案

不要忘记绘制阴影必须使用硬件加速绘图

<application android:hardwareAccelerated="true" ...>

详见 https://developer.android.com/guide/topics/graphics/hardware-accel.html?hl=ru

关于android - CardView 不显示阴影高程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43406938/

相关文章:

android - 将外部 JAR 作为外部 SDK 添加到 Android 项目,例如 Dropbox sdk 或其他类型的第三方 sdk

java - 汉堡图标不显示?

xml - 在 Angular 2 中将 XML 插入 DOM

python - LXML 的 etree.tostring 在链接 href 属性中转义 url

android - 如何在 "Add account " Activity 完成时收到通知

android - 如何在程序代码中启用 Android 上的位置?

xml - 如何在 Scala 类中漂亮地表示 XML 实体?

android - 动态卡片 View 与 Firebase 相结合

android - RecyclerView 中的 CardView 和 OnClickListener 问题

java - CardView背景颜色变化