我正在制作一个聊天应用程序。因此,如果消息是图像类型的,我想要换行高度并固定宽度。但问题是,由于图像需要一些时间才能加载,因此在图像加载之前,聊天消息会发生变化,因此会出现抖动。我该怎么处理呢?
<android.support.constraint.ConstraintLayout
android:id="@+id/parent_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/send_message_box"
android:maxWidth="228dp">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/iv_message"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="200dp"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:padding="11dp"
android:visibility="gone" />
</android.support.constraint.ConstraintLayout>这是我正在使用的图像布局。
发布于 2019-04-20 05:07:03
您可以固定高度并显示占位符图像,直到图像加载。您可以使用毕加索获得显示占位符图像(直到图像加载)的功能,请查看此https://square.github.io/picasso/
发布于 2019-04-20 05:10:38
您可以在下载图像时使用默认图像设置初始高度。图片下载完成后,如果将height设置为wrap_content,则取图片的高度。因此,您需要修改ImageView,如下所示。
<ImageView
android:id="@+id/iv_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@mipmap/ic_image_loader_placeholder" />请根据您的需求修改ImageView。
您可能还会看到这个Github project,我在其中实现了一个类似的想法。我必须调用Flickr的API并将图像加载到RecyclerView中。希望这能有所帮助!
https://stackoverflow.com/questions/55767695
复制相似问题