通过XML定义的卡片视图在Android工作室预览中没有显示其正确的圆角(它们被子视图覆盖)。
虽然它在模拟器中渲染后显示得很好,但我担心这种“故障”可能是我做错事或忘记某些关键属性的症状。即使它不是更深层次问题的症状,任何人都可以提供有关如何解决这种美学错误的任何见解吗?
有谁可以权衡这个?
<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>
生成的预览中的问题是CardView
中的内容没有被剪切到CardView
的边界,所以你看到的角落是ImageView
的角落,当你在模拟器/设备上运行时它实际上被剪裁了。
如果您真的想要生成类似于真实的预览,可以尝试这种解决方法。
<?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>
ImageView
命名空间下tools:
的背景。
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@android:color/holo_blue_bright"
tools:src="@drawable/test" />
Android Studio支持tools:
namespace中的各种XML属性,这些属性支持设计时功能(例如src
的ImageView
在预览模式下显示)。
这里圆角通常显示您的代码。我的测试手机是Android 7.1。所以我认为你应该清除手机的缓存并再次安装这个应用程序。或者你应该增加价值
应用:cardCornerRadius
然后再测试一下。