【问题标题】:Why does my image appear in Android Studio design view but not when run in phone?为什么我的图像出现在 Android Studio 设计视图中,但在手机中运行时却没有?
【发布时间】:2021-10-01 06:18:51
【问题描述】:

在我的设计视图中,我的应用看起来像this,但是当它在我的手机上运行时,它看起来像this,底部的cardBoardViews 没有任何图像。有谁知道为什么会这样? 我的 cardBoardView 代码是这样的:

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <androidx.cardview.widget.CardView
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="5dp"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="20dp"
                app:cardElevation="3dp"
                app:cardMaxElevation="20dp">


                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:srcCompat="@drawable/vector_illustration" />
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="5dp"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="20dp"
                app:cardElevation="3dp"
                app:cardMaxElevation="20dp">


                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:srcCompat="@drawable/vector_illustration" />
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="5dp"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="20dp"
                app:cardElevation="3dp"
                app:cardMaxElevation="20dp">


                <ImageView

                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:srcCompat="@drawable/vector_illustration" />
            </androidx.cardview.widget.CardView>
        </LinearLayout>

我的完整代码是:

<?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="@color/light_grey"
    >

<ScrollView
    android:id="@+id/scrollView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">

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

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:elevation="3dp"
            >


            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/backgroud_beranda" />

            <TextView
                android:id="@+id/judulRongsokin"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_marginLeft="20dp"
                android:fontFamily="@font/katsudon"
                android:text="@string/app_name"
                android:textColor="@color/white"
                android:textSize="30dp"
                app:layout_constraintBottom_toBottomOf="@+id/logo"
                app:layout_constraintStart_toEndOf="@+id/logo"
                app:layout_constraintTop_toTopOf="@+id/logo" />

            <TextView
                android:id="@+id/profil"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_marginStart="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="50dp"
                android:layout_marginEnd="20dp"
                android:layout_marginRight="20dp"
                android:background="@drawable/profil_background"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:shadowColor="@color/black"
                android:text="@string/username"
                android:textColor="@color/black"
                android:textSize="30dp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/logo" />

            <ImageView
                android:id="@+id/logo"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginStart="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/logo" />

            <TextView
                android:id="@+id/saldo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginBottom="20dp"
                android:text="Rp. 9.999"
                android:textSize="20dp"
                android:textStyle="bold"
                android:textColor="@color/black"
                app:layout_constraintBottom_toBottomOf="@+id/profil"
                app:layout_constraintEnd_toEndOf="@+id/profil" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingStart="20dp"
            android:paddingTop="20dp"
            android:paddingEnd="20dp">

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

                <androidx.cardview.widget.CardView
                    android:id="@+id/rongsokin_barang"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_centerInParent="true"
                    android:layout_marginStart="5dp"
                    android:layout_marginEnd="5dp"
                    app:cardBackgroundColor="@color/white"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="5dp"
                    app:cardMaxElevation="10dp">

                    <ImageView
                        android:id="@+id/image1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:paddingTop="15dp"
                        android:paddingBottom="15dp"
                        app:srcCompat="@drawable/logo_rongsok" />
                </androidx.cardview.widget.CardView>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:text="Rongsokin Barang"
                    android:gravity="center"
                    android:textAlignment="center"
                    android:textColor="@color/black" />

            </LinearLayout>

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

                <androidx.cardview.widget.CardView
                    android:id="@+id/cari_lokasi"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_centerInParent="true"
                    android:layout_marginStart="5dp"
                    android:layout_marginEnd="5dp"
                    app:cardBackgroundColor="@color/white"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="5dp"
                    app:cardMaxElevation="10dp">

                    <ImageView
                        android:id="@+id/image2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:paddingTop="15dp"
                        android:paddingBottom="15dp"
                        app:srcCompat="@drawable/logo_location" />
                </androidx.cardview.widget.CardView>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:text="Cari Lokasi Terdekat"
                    android:gravity="center"
                    android:textAlignment="center"
                    android:textColor="@color/black" />
            </LinearLayout>

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

                <androidx.cardview.widget.CardView
                    android:id="@+id/komunitas"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_centerInParent="true"
                    android:layout_marginStart="5dp"
                    android:layout_marginEnd="5dp"
                    app:cardBackgroundColor="@color/white"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="5dp"
                    app:cardMaxElevation="10dp">

                    <ImageView
                        android:id="@+id/image3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:paddingLeft="15dp"
                        android:paddingTop="15dp"
                        android:paddingRight="15dp"
                        android:paddingBottom="15dp"
                        app:srcCompat="@drawable/logo_community" />
                </androidx.cardview.widget.CardView>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:text="Komunitas Kami"
                    android:gravity="center"
                    android:textAlignment="center"
                    android:textColor="@color/black" />
            </LinearLayout>

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

                <androidx.cardview.widget.CardView
                    android:id="@+id/dompet"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_centerInParent="true"
                    android:layout_marginStart="5dp"
                    android:layout_marginEnd="5dp"
                    app:cardBackgroundColor="@color/white"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="5dp"
                    app:cardMaxElevation="10dp">

                    <ImageView
                        android:id="@+id/image4"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:paddingLeft="15dp"
                        android:paddingTop="15dp"
                        android:paddingRight="15dp"
                        android:paddingBottom="15dp"
                        app:srcCompat="@drawable/logo_wallet" />
                </androidx.cardview.widget.CardView>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:text="Dompet Rongsokin"
                    android:gravity="center"
                    android:textAlignment="center"
                    android:textColor="@color/black" />
            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="15dp"
            >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Kenali RONGSOKIN Lebih Dekat"
                android:textStyle="bold"
                android:textColor="@color/black"
                android:textSize="18sp"
                android:paddingLeft="20dp"
                android:paddingBottom="5dp"
                />
            <ImageView
                android:id="@+id/garis"
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="@drawable/rect_yellow_gradient"
                android:gravity="center_horizontal"
                 />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <androidx.cardview.widget.CardView
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="5dp"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="20dp"
                app:cardElevation="3dp"
                app:cardMaxElevation="20dp">


                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:srcCompat="@drawable/vector_illustration" />
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="5dp"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="20dp"
                app:cardElevation="3dp"
                app:cardMaxElevation="20dp">


                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:srcCompat="@drawable/vector_illustration" />
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="5dp"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="20dp"
                app:cardElevation="3dp"
                app:cardMaxElevation="20dp">


                <ImageView

                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:srcCompat="@drawable/vector_illustration" />
            </androidx.cardview.widget.CardView>
        </LinearLayout>

    </LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android xml user-interface android-cardview


    【解决方案1】:

    这可能是因为您正在使用size of the image,请尝试缩小图像大小再试一次

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多