为什么图片内容未显示在 avd 的 scrollView 中,但显示了滚动条

问题描述

我使用了水平滚动视图,在里面我放了一个线性布局,然后是一些图片,但是在 avd 上我看不到图片但是可以看到滚动条。我也可以水平滚动滚动条,唯一的问题是我的图片没有显示

在horizo​​ntalScrollbar里面的xml代码下面:

    tools:context=".MainActivity">

<horizontalscrollview
    android:id="@+id/horizontalscrollview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="112dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="400dp"
            android:layout_height="402dp"
            android:layout_weight="0"
            android:contentDescription="@string/img3"
            android:visibility="visible"
            tools:srcCompat="@tools:sample/backgrounds/scenic" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="420dp"
            android:layout_height="262dp"
            android:layout_gravity="center"
            android:layout_weight="0"
            android:contentDescription="@string/img"
            tools:srcCompat="@drawable/ic_launcher_background" />

        <ImageView
            android:id="@+id/imageVie3"
            android:layout_width="400dp"
            android:layout_height="260dp"
            android:layout_gravity="center"
            android:layout_weight="0"
            android:contentDescription="@string/img2"
            tools:srcCompat="@drawable/img1" />

    </LinearLayout>
</horizontalscrollview>

解决方法

tools:srcCompat 改为 app:srcCompat

例如

从此:

tools:srcCompat="@tools:sample/backgrounds/scenic"

为此:

app:srcCompat="@tools:sample/backgrounds/scenic"

tools 行仅用于预览和界面构建器。