【问题标题】:CardView is causing app to crash (shown in the picture)CardView 导致应用程序崩溃(如图所示)
【发布时间】:2020-08-10 01:14:31
【问题描述】:

我每次运行代码时都会崩溃,我尝试删除 CardView 代码,但它不再崩溃了。你能帮帮我吗,因为我是这个环境的新手,目前我正在做一个项目,我对 cardView 代码做错了吗?谢谢

crashed app

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bgapps"
    tools:context=".utama">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp">

            <androidx.cardview.widget.CardView
                android:id="@+id/cardCam"
                android:layout_width="120dp"
                android:layout_height="125dp"
                android:layout_below="@+id/cardPupuk"
                android:layout_marginStart="125dp"
                android:layout_marginTop="40dp"
                android:layout_marginEnd="@+id/soilIv"
                app:cardBackgroundColor="#989595"
                app:cardCornerRadius="12dp">

                <ImageView
                    android:id="@+id/camIv"
                    android:layout_width="71dp"
                    android:layout_height="71dp"
                    android:layout_gravity="center"
                    android:src="@drawable/cam" />
            </androidx.cardview.widget.CardView>
        </RelativeLayout>
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 请您告知错误,您将在 android studio 底部的 logcat 中获取它们,我也想知道如果您提供任何约束,为什么要使用约束布局它指导孩子

标签: java android crash cardview


【解决方案1】:

android:layout_marginEnd

在此视图的末端指定额外的空间。这个空间是 在这个视图的范围之外。边距值应为正数。

您应该在 androidx.cardview.widget.CardView 部分使用适当的值。

不要

 android:layout_marginEnd="@+id/soilIv"

应该是

android:layout_marginEnd="10dp"

【讨论】:

  • 天哪,谢谢它成功了dddddd。我希望你有一个美好的伙伴。非常感谢
  • @Ranss 欢迎。继续前进。
猜你喜欢
  • 1970-01-01
  • 2014-09-23
  • 1970-01-01
  • 2015-10-21
  • 2016-06-04
  • 2011-08-24
  • 2014-05-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多