【问题标题】:My images are not shown in a recyclerView in android emulator我的图像未显示在 android 模拟器的 recyclerView 中
【发布时间】:2021-01-17 05:34:41
【问题描述】:

您好,我正在使用为 M1 机器 https://github.com/google/android-emulator-m1-preview 创建的这个模拟器。我从moviesApi获取海报路径。但是在其他设备中,它们在recyclerview中绘制得很好,当我在我的moto g6中模拟它时,也会发生这个问题。

显示的图像是xml中设置的图像,如下所示。

  <ImageView
                android:id="@+id/rv_image_movie"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:background="@drawable/movies_noimage"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

            </ImageView>

改造响应是完美的,正如我评论的那样,它可以在其他模拟器 api 26 27 28 中工作,任何你命名的。但是在这个和 motog6 中不起作用,一定是有问题。

这很奇怪,因为在 m1 支持的模拟器中,我的 rick and morty 应用程序完美地显示了图像。

【问题讨论】:

    标签: android android-emulator virtual-device-manager


    【解决方案1】:

    好的,我找到了答案,它可能会帮助很多人。要解决此问题,您需要在您的 android 清单中添加...

      <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    
    <application
        android:name=".MovieApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
    
        android:theme="@style/Theme.MoviesDBKotlin">
        <activity
            android:name=".ui.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.MoviesDBKotlin">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
    

    add android:usesCleartextTraffic="true" 将修复模拟器问题,在我的情况下与 glide 有关,我认为是这样。享受吧!!。

    【讨论】:

    • 问题不在于滑行!这是因为您尝试从非 HTTPS 链接加载图像。使用 HTTPS 版本,问题将得到解决。默认情况下,限制从 HTTP 版本加载资源。
    • 在 9 和更高版本(可能是 8+)的较新 api 中,您必须使用 HTTPS,否则您的网络调用将被阻止。
    • 哇,你们俩都是对的,我认为我们在这篇文章中帮助了其他人。并感谢您的回复
    猜你喜欢
    • 2020-07-18
    • 1970-01-01
    • 2013-08-23
    • 2021-04-23
    • 2012-04-16
    • 1970-01-01
    • 2011-02-16
    • 2017-01-01
    • 1970-01-01
    相关资源
    最近更新 更多