Hi I am displaying image stored in my phone using URI and Picasso library and it is displayed correctly when I do it in new Activity without ScrollView but when I do the same in my original activity layout that contains two card views with Linear Layout and ScrollView image is not displayed but blank image colored with app's primary color is shown.

Here is my TryActivity code where everything is working fine:

<FrameLayout 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=".ui.TryActivity">

<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="370dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="8dp"
    android:padding="10dp"
    app:cardCornerRadius="10dp"
    app:cardElevation="5dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="12dp"
        android:paddingTop="8dp">

        <TextView
            android:id="@+id/time_const"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:text="@string/time_const"
            android:textColor="@android:color/black"
            android:textAppearance="?android:textAppearanceMedium"
            android:textStyle="italic"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.24"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/pic_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="12dp"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/darker_gray"
            android:textStyle="bold"
            app:layout_constraintBaseline_toBaselineOf="@+id/time_const"
            app:layout_constraintStart_toEndOf="@+id/time_const" />

        <ImageView
            android:id="@+id/camera_pic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:tint="@color/colorPrimary"
            android:contentDescription="@string/app_name"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:srcCompat="@drawable/camera" />

        <ImageView
            android:id="@+id/click_click"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:maxHeight="250dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="16dp"
            android:contentDescription="@string/app_name"
            app:layout_constraintBottom_toTopOf="@+id/camera_pic"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/time_const"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

</FrameLayout> 

Here is my Java code for this activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_try);

    ImageView imageView = findViewById(R.id.click_click);

    Picasso.get()
            .load("file:/storage/emulated/0/Pictures/JPEG_20190330_190925_8486610829519670776.jpg")
            .into(imageView);
}

enter image description here

But if i try to do same in my original activity it doesn't work:

Here is my xml layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="16dp"
    android:paddingBottom="32dp"
    tools:context=".ui.DetailsActivity"
    tools:showIn="@layout/activity_details">

    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        app:cardCornerRadius="10dp"
        app:cardElevation="5dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="12dp"
            android:paddingTop="8dp">

            <TextView
                android:id="@+id/p_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:textAppearance="?android:textAppearanceLarge"
                android:textColor="@color/colorPrimary"
                android:textStyle="italic|bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/p_occupation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="5dp"
                android:layout_marginEnd="8dp"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/darker_gray"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/p_name" />

            <TextView
                android:id="@+id/loc_const"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="8dp"
                android:text="@string/loc_const"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/holo_red_dark"
                android:textStyle="italic"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.14"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/p_occupation" />

            <TextView
                android:id="@+id/p_city"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="12dp"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/black"
                app:layout_constraintBaseline_toBaselineOf="@+id/loc_const"
                app:layout_constraintStart_toEndOf="@+id/loc_const" />

            <TextView
                android:id="@+id/sal_const"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:text="@string/sal_const"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/holo_red_dark"
                android:textStyle="italic"
                app:layout_constraintEnd_toEndOf="@+id/loc_const"
                app:layout_constraintTop_toBottomOf="@+id/loc_const" />

            <TextView
                android:id="@+id/p_sal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/black"
                app:layout_constraintBaseline_toBaselineOf="@+id/sal_const"
                app:layout_constraintStart_toStartOf="@+id/p_city" />

            <TextView
                android:id="@+id/date_const"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:text="@string/date_const"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/holo_red_dark"
                android:textStyle="italic"
                app:layout_constraintEnd_toEndOf="@+id/sal_const"
                app:layout_constraintTop_toBottomOf="@+id/sal_const" />

            <TextView
                android:id="@+id/p_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/black"
                app:layout_constraintBaseline_toBaselineOf="@+id/date_const"
                app:layout_constraintStart_toStartOf="@+id/p_sal" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="370dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:padding="10dp"
        app:cardCornerRadius="10dp"
        app:cardElevation="5dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="12dp"
            android:paddingTop="8dp">

            <TextView
                android:id="@+id/time_const"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:text="@string/time_const"
                android:textColor="@android:color/black"
                android:textAppearance="?android:textAppearanceMedium"
                android:textStyle="italic"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.24"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/pic_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="12dp"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/darker_gray"
                android:textStyle="bold"
                app:layout_constraintBaseline_toBaselineOf="@+id/time_const"
                app:layout_constraintStart_toEndOf="@+id/time_const" />

            <ImageView
                android:id="@+id/camera_pic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"
                android:tint="@color/colorPrimary"
                android:contentDescription="@string/app_name"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:srcCompat="@drawable/camera" />

            <ImageView
                android:id="@+id/clicked_pic"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:maxHeight="250dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="16dp"
                android:contentDescription="@string/app_name"
                app:layout_constraintBottom_toTopOf="@+id/camera_pic"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/time_const"/>

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

</LinearLayout>

</ScrollView>

Here is the screenshot without the image being displayed:

Current Problem Screenshot

Answer

I did a silly mistake here i was setting that clicked image in app icon image that's why it was stretched with app's primary color. This took few hours from my day!!

  • 1
Reply Report
      • 1
    • Nice you have figured out. If possible, please, check your answer as the correct one. It is correct to do so. It shows another users the question is done. Thanks and keep coding. Plus one.

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions