**已解决** Uri图片未显示在ScrollView

时间:2019-03-30 15:49:12

标签: android android-layout picasso

嗨,我正在显示使用URI和Picasso库存储在手机中的图像,当我在没有ScrollView的新Activity中执行此操作时,但在包含两个带有线性布局的卡片视图的原始活动布局中执行相同操作时,该图像正确显示并且不显示ScrollView图像,但显示带有应用程序原色的空白图像。

这是我的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代码:

@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

但是,如果我尝试在原始活动中执行相同的操作,则将无效:

这是我的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>

这是没有显示图像的屏幕截图:

Current Problem Screenshot

1 个答案:

答案 0 :(得分:1)

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