Uri 图像未显示在 ScrollView 中

Uri Image not displayed inside ScrollView

您好,我正在使用 URI 和 Picasso 库显示存储在我的 phone 中的图像,当我在没有 ScrollView 的新 Activity 中执行此操作时它可以正确显示,但是当我在我的原始文件中执行相同操作时activity 包含两个带有线性布局和滚动视图的卡片视图的布局不会显示图像,但会显示用应用程序的原色着色的空白图像。

这是我的 TryActivity 代码,一切正常:

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

这是我的 Java 代码 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);
}

但是如果我尝试在我的原始 activity 中做同样的事情,它不起作用:

这是我的 xml 布局:

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

这里是没有显示图片的截图:

我在这里犯了一个愚蠢的错误,我在应用程序图标图像中设置了点击图像,这就是为什么它被拉伸为应用程序的原色。这从我的一天开始就花了几个小时!!