Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CardView圆角未显示在Android预览中 我的问题_Android_Android Studio_Android Studio 3.0 - Fatal编程技术网

CardView圆角未显示在Android预览中 我的问题

CardView圆角未显示在Android预览中 我的问题,android,android-studio,android-studio-3.0,Android,Android Studio,Android Studio 3.0,通过XML定义的我的卡片视图在Android studio预览中没有显示其正确的圆角(它们被其子视图覆盖) 虽然在模拟器中渲染后显示良好,但我担心这个“小故障”可能是我做错了什么或忘记了一些关键属性的症状。即使这不是一个更深层次问题的征兆,有人能提供一些关于如何修复这个美学错误的见解吗 有人能参与进来吗 <android.support.v7.widget.CardView android:layout_marginTop="16dp" android:layout_mar

通过XML定义的我的卡片视图在Android studio预览中没有显示其正确的圆角(它们被其子视图覆盖)

虽然在模拟器中渲染后显示良好,但我担心这个“小故障”可能是我做错了什么或忘记了一些关键属性的症状。即使这不是一个更深层次问题的征兆,有人能提供一些关于如何修复这个美学错误的见解吗

有人能参与进来吗

<android.support.v7.widget.CardView
    android:layout_marginTop="16dp"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="16dp"

    app:cardCornerRadius="10dp"

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.AppCompatImageView
        android:src="@color/red"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

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

Android模拟器屏幕截图

此处圆角通常与代码一起显示。我的测试手机是安卓7.1。所以我认为你应该清除手机的缓存,然后重新安装这个应用程序。或者你应该增加

应用程序:cardCornerRadius


然后再次测试。

生成的预览中的问题是,
CardView
中的内容没有被剪裁到
CardView
的边界,因此您看到的角点是
ImageView
的角点,当您在emulator/设备上运行时,实际上会被剪裁

如果您真的想生成真实的预览,可以尝试此解决方法

  • 添加具有所需拐角半径的可绘制短桩

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="rectangle">
    
      <corners android:radius="20dp" />
      <solid android:color="@android:color/holo_green_light" />
    
    </shape>
    

  • Android Studio在中支持多种XML属性,以启用设计时功能(例如,
    ImageView
    src
    在预览模式下显示)。

    它也在Android Studio预览中正常显示吗?@AlanSTACK,在Android Studio预览中,我可以看到CardView的圆角,但它被AppCompatImageView隐藏。
    <ImageView android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@android:color/holo_blue_bright"
      tools:src="@drawable/test" />