简体   繁体   中英

Why does my image appear in Android Studio design view but not when run in phone?

In my design view, my app look like this but when it run on my phone, it look like this , my cardBoardViews at the bottom don't have any image. Anyone know why this happen? My code for the cardBoardView is this:

<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>

My full code is:

<?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>

这可能是因为size of the image您使用,尽量减少图像的大小,然后再试一次

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM