为什么Android Studio不显示某些CardView的布局

问题描述

我有一个奇怪的问题。我有2个Cardview我想用于(不同的)RecyclerViews。当Android Studio在布局编辑器中正确显示一个设计时,另一个布局却无法正确显示在这里,您有两个视图。 无法正确显示布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="5dp"
    app:cardElevation="0dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true"
    app:contentPadding="0dp"
    card_view:cardBackgroundColor="@android:color/transparent"
    app:contentPaddingBottom="0dp"
    app:contentPaddingLeft="7dp">

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



        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="2dp"
            android:adjustViewBounds="true"/>




        </LinearLayout>

</androidx.cardview.widget.CardView>

在这里您会在布局编辑器中看到显示的布局:

Not correctly displayed layout

在这里,您在布局编辑器中具有正确显示的布局的XML代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="10dp"
    app:cardElevation="2dp"
    app:cardPreventCornerOverlap="true"
    app:cardUseCompatPadding="true"
    app:contentPadding="12dp"
    app:contentPaddingBottom="0dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="4dp">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:padding="2dp" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="0dp"
            android:text="Line1"
            android:textColor="@android:color/black"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Line2"
            android:layout_marginTop="22dp"
            android:layout_marginLeft="50dp"
            android:textSize="15sp" />



    </RelativeLayout>


</androidx.cardview.widget.CardView>

这里是布局编辑器的对应屏幕截图

enter image description here

问题在于在CardView中显示不正确,我无法立即看到更改的效果,这非常不便。此外,我只是不明白为什么一个显示正确而另一个显示不正确。您有什么想法我可以解决这个问题吗?我会很感激每个评论

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...