如何解决为什么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>
在这里,您在布局编辑器中具有正确显示的布局的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>
问题在于在CardView中显示不正确,我无法立即看到更改的效果,这非常不便。此外,我只是不明白为什么一个显示正确而另一个显示不正确。您有什么想法我可以解决这个问题吗?我会很感激每个评论。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。