Mirnox
Mirnox

Reputation: 3

imageview seems to be invisible

i got a problem with imageView not displaying my image in android studio. The image is displayed in layout editor but when i launch the emulator the imageView act just like if i had set the visibility on " invisible" : the image is not appearing but it still take up the space of my imageview.

imaview 16 at the end of the xml. Xml :

<RelativeLayout 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"
    tools:context=".QuizActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical"
        android:foregroundGravity="center_horizontal"
        android:gravity="center_horizontal"
        android:background="@color/white"
        android:elevation="1dp"
        android:layout_alignParentBottom="false">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:background="@drawable/etape_1"></LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="left">


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

                <Button
                    android:id="@+id/btnAcc"
                    android:background="@drawable/home"
                    android:layout_width="45dp"
                    android:layout_height="45dp" />

                <TextView
                    android:text="Accueil"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView7"
                    android:textColor="@color/black"
                    android:textSize="21sp" />
            </LinearLayout>

        </LinearLayout>

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal"
            android:textColor="@color/black"
            android:textStyle="bold"
            android:textSize="24sp" />

        <ImageView
            app:srcCompat="@drawable/black"
            android:id="@+id/imageView13"
            android:layout_marginTop="10dp"
            android:visibility="visible"
            android:layout_width="36dp"
            android:layout_height="9dp" />

        <ViewFlipper
            android:layout_width="match_parent"
            android:id="@+id/viewFlipper"
            android:foregroundGravity="center_horizontal"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="20dp">

            <RadioGroup
                android:id="@+id/radioGroup1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:baselineAligned="false"
                android:measureWithLargestChild="false"
                android:gravity="left|center_vertical"
                android:layout_gravity="center">

                <RadioButton
                    android:id="@+id/radio0"
                    android:layout_height="wrap_content"
                    android:text="Test"
                    android:background="@drawable/checkbox_background"
                    android:textColor="@color/white"
                    android:layout_marginBottom="20dp"
                    android:checked="true"
                    android:gravity="center|start"
                    android:textSize="27sp"
                    android:padding="10dp"
                    android:layout_width="350dp"
                    android:buttonTint="@color/white" />

                <RadioButton
                    android:id="@+id/radio1"
                    android:text="Test"
                    android:background="@drawable/checkbox_background"
                    android:layout_marginBottom="20dp"
                    android:layout_height="wrap_content"
                    android:textColor="@color/white"
                    android:gravity="center|start"
                    android:textSize="27sp"
                    android:padding="10dp"
                    android:layout_width="350dp"
                    android:breakStrategy="simple"
                    android:checked="false"
                    android:buttonTint="@color/white" />

                <RadioButton
                    android:id="@+id/radio2"
                    android:layout_height="wrap_content"
                    android:text="Test"
                    android:background="@drawable/checkbox_background"
                    android:textColor="@color/white"
                    android:layout_marginBottom="20dp"
                    android:gravity="center|start"
                    android:textSize="27sp"
                    android:padding="10dp"
                    android:layout_width="350dp"
                    android:buttonTint="@color/white"/>

                <RadioButton
                    android:layout_height="wrap_content"
                    android:text="Test"
                    android:id="@+id/radio3"
                    android:background="@drawable/checkbox_background"
                    android:textColor="@color/white"
                    android:layout_marginBottom="20dp"
                    android:textSize="27sp"
                    android:padding="10dp"
                    android:layout_width="350dp"
                    android:buttonTint="@color/white" />

                <RadioButton
                    android:layout_height="wrap_content"
                    android:text="Test"
                    android:id="@+id/radio4"
                    android:background="@drawable/checkbox_background"
                    android:textColor="@color/white"
                    android:layout_marginBottom="20dp"
                    android:textSize="27sp"
                    android:padding="10dp"
                    android:layout_width="350dp"
                    android:buttonTint="@color/white"/>

                <RadioButton
                    android:layout_height="wrap_content"
                    android:text="Test"
                    android:id="@+id/radio5"
                    android:textColor="@color/white"
                    android:background="@drawable/checkbox_background"
                    android:scrollHorizontally="false"
                    android:textSize="27sp"
                    android:padding="10dp"
                    android:layout_width="350dp"
                    android:buttonTint="@color/white"
                    android:textColorHint="@color/white" />

            </RadioGroup>
        </ViewFlipper>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_marginTop="10dp">

            <Button
                android:id="@+id/button1"
                android:background="@drawable/checkbox_background"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:elevation="0dp"
                android:layout_marginRight="100dp"
                android:text="Valider"
                android:textColor="@color/white"
                android:padding="10dp"
                android:textAllCaps="false"
                android:textSize="21sp" />

            <ImageView
                android:layout_width="45dp"
                android:layout_height="45dp"
                app:srcCompat="@drawable/home"
                android:id="@+id/imaView16"
                android:visibility="visible"
                android:layout_alignParentTop="false" />

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

Upvotes: 0

Views: 1025

Answers (4)

Sartaj
Sartaj

Reputation: 1

The solution that worked for me is to rename the image without any special characters.

Upvotes: 0

Prokash Sarkar
Prokash Sarkar

Reputation: 11873

app:srcCompat is generally used for vector type drawable. If you are are using vector drawable make sure the vector drawable color is different from the background color. Also re-check the below things,

A. Increase the layout_height of you ImageView (The current dp might be too small to display the image)

B. for non-vector drawable use android:src with a solid background in android:background just to make sure the image is showing.

Upvotes: 0

W4R10CK
W4R10CK

Reputation: 5550

In your ImageView you must use android:src not app:srcCompat, So:

Change this:

app:srcCompat="@drawable/black"

With this:

android:src="@drawable/black"

Upvotes: 1

EtherPaul
EtherPaul

Reputation: 423

change app:srcCompat="@drawable/black" to android:background="@drawable/black"

Upvotes: 0

Related Questions