【问题标题】:How can I get height of ImageView in RecyclerView.Adapter如何在 RecyclerView.Adapter 中获取 ImageView 的高度
【发布时间】:2015-07-10 10:21:13
【问题描述】:

我正在使用RecyclerViewStaggeredGridLayoutManager,其中显示CardViewImageViewTextView。图片应该是方形的,所以在布局资源文件中我设置了android:layout_width="match_parent",现在我需要设置高度等于这个宽度。我尝试在Adapter 中执行此操作,它在onBindViewHolder 方法中扩展RecyclerView.Adapter,但getMeasuredWidth 始终返回0。我在Activity 的 onResume 方法中将适配器设置为RecyclerView。我该怎么做?

【问题讨论】:

  • @Graeme,它不起作用。据我了解,当您在布局资源文件中设置图像源时,此方法有效

标签: android android-adapter android-recyclerview


【解决方案1】:

我想这是onResume方法完成时的情况,图像尚未设置在UI屏幕上,因为它会花费时间。 位图异步框架可能会对您有所帮助,例如 xutils[UniversalImageLoader][1]。可以在位图下载完成后进行缩放,也可以从服务器获取图片宽度,可能还有其他解决方案。

【讨论】:

    猜你喜欢
    • 2014-05-01
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 2011-09-24
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多