Fresco 图像在 Android Jellybean 设备上的 Recyclerview 中不可见
Fresco image not visible in Recyler View on Android Jellybean devices
在 Android Jellybean 设备上的 RecyclerView 中使用 fresco 时,加载图像时会出现一条细线并且图像不可见,但同样适用于 KitKat+ 设备。
Samsung - 4.1.1 - API 16 - 768 X 1280
SamsungGalaxyNote2 - 4.3 - API 18 - 720 X 1280
NOTE : Have tested in multiple devices and the scenario is the same
这就是我们在库中使用它的方式
if (newsModelStoreList.get(position-1).getImageUrl() != null) {
String imageUrl = newsModelStoreList.get(position-1).getImageUrl();
String extension=".jpg";
try {
extension = imageUrl.substring(imageUrl.lastIndexOf("."));
}
catch (Exception e)
{
}
Log.d("extension: ",extension);
if(extension.equals(".gif")) {
Log.d("Detected Gif: ", "Starting gif controller");
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(Uri.parse(imageUrl))
.setAutoPlayAnimations(true)
.build();
myHolder.newsImage.setController(controller);
}
else
{
myHolder.newsImage.setImageURI(Uri.parse(imageUrl));
}
}
I AM 100% SURE THAT URL IS AVAILABLE AND IS WORKING ON 4.4+ DEVICES
这是充气的 news_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/feed_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_parent_rounded_corner"
android:layout_marginTop="@dimen/feed_item_margin"
android:orientation="vertical"
android:paddingBottom="@dimen/feed_item_padding_top_bottom"
android:paddingTop="@dimen/feed_item_padding_top_bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:gravity="right"
android:layout_height="wrap_content">
<TextView
android:id="@+id/timestamp"
android:gravity="right"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="posted 5 min ago"
android:textColor="@color/timestamp"
android:textSize="@dimen/feed_item_timestamp" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/newsTitle"
android:textSize="22dp"
android:clickable="false"
android:textStyle="bold"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:textColor="@color/black"
android:textColorLink="@color/com_facebook_blue"
android:layout_marginBottom="5dp"
android:paddingBottom="5dp"
/>
<TextView
android:id="@+id/newsInformation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:textColor="@color/black"
android:textColorLink="@color/com_facebook_blue"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:paddingTop="@dimen/feed_item_status_pad_top" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/viewMore" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_height="wrap_content">
</LinearLayout>
SimpleDraweeView is used here ...
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:visibility="visible"
android:adjustViewBounds="true"
android:id="@+id/newsImage"/>
The rest of the xml is just for reference just in case it would help
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/pad_5dp">
<TextView
android:id="@+id/awesomeness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/timestamp"
android:text="Awesomeness: "
android:textSize="@dimen/feed_item_timestamp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/awesomenessCountNumber"
android:text="0"
android:textColor="@color/timestamp"
android:textSize="@dimen/feed_item_timestamp"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/pad_5dp"
android:layout_marginLeft="@dimen/pad_5dp"
android:layout_marginRight="@dimen/pad_5dp">
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/awesomeButton"
android:layout_marginRight="8dp"
android:background="@drawable/awesome_button_2"/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/facebookSharePost"
android:layout_marginRight="8dp"
android:background="@drawable/facebook_icon"
/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/whatsApp"
android:background="@drawable/whats_app_icon"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:layout_marginRight="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report"/>
<Button
android:layout_marginRight="6dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/report"
android:background="@drawable/report_empty" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
猜猜你做错了什么:
- 您正在使用
wrap_content.
Fresco 不支持此功能,除非您还提供 fresco:viewAspectRatio.
请参阅 guide to Drawees and the longer explanation 关于 wrap_content。
- 您正在使用
android:scaleType
。这对 SimpleDraweeViews 没有影响。您需要使用 fresco:actualImageScaleType
。还要确保 fitXY
确实是您想要的;这不会保留纵横比。请参阅 scale types. 上的文档
在 Android Jellybean 设备上的 RecyclerView 中使用 fresco 时,加载图像时会出现一条细线并且图像不可见,但同样适用于 KitKat+ 设备。
Samsung - 4.1.1 - API 16 - 768 X 1280
SamsungGalaxyNote2 - 4.3 - API 18 - 720 X 1280
NOTE : Have tested in multiple devices and the scenario is the same
这就是我们在库中使用它的方式
if (newsModelStoreList.get(position-1).getImageUrl() != null) {
String imageUrl = newsModelStoreList.get(position-1).getImageUrl();
String extension=".jpg";
try {
extension = imageUrl.substring(imageUrl.lastIndexOf("."));
}
catch (Exception e)
{
}
Log.d("extension: ",extension);
if(extension.equals(".gif")) {
Log.d("Detected Gif: ", "Starting gif controller");
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(Uri.parse(imageUrl))
.setAutoPlayAnimations(true)
.build();
myHolder.newsImage.setController(controller);
}
else
{
myHolder.newsImage.setImageURI(Uri.parse(imageUrl));
}
}
I AM 100% SURE THAT URL IS AVAILABLE AND IS WORKING ON 4.4+ DEVICES
这是充气的 news_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/feed_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_parent_rounded_corner"
android:layout_marginTop="@dimen/feed_item_margin"
android:orientation="vertical"
android:paddingBottom="@dimen/feed_item_padding_top_bottom"
android:paddingTop="@dimen/feed_item_padding_top_bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:gravity="right"
android:layout_height="wrap_content">
<TextView
android:id="@+id/timestamp"
android:gravity="right"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="posted 5 min ago"
android:textColor="@color/timestamp"
android:textSize="@dimen/feed_item_timestamp" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/newsTitle"
android:textSize="22dp"
android:clickable="false"
android:textStyle="bold"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:textColor="@color/black"
android:textColorLink="@color/com_facebook_blue"
android:layout_marginBottom="5dp"
android:paddingBottom="5dp"
/>
<TextView
android:id="@+id/newsInformation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:textColor="@color/black"
android:textColorLink="@color/com_facebook_blue"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:paddingTop="@dimen/feed_item_status_pad_top" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/viewMore" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_height="wrap_content">
</LinearLayout>
SimpleDraweeView is used here ...
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:visibility="visible"
android:adjustViewBounds="true"
android:id="@+id/newsImage"/>
The rest of the xml is just for reference just in case it would help
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/pad_5dp">
<TextView
android:id="@+id/awesomeness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/timestamp"
android:text="Awesomeness: "
android:textSize="@dimen/feed_item_timestamp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/awesomenessCountNumber"
android:text="0"
android:textColor="@color/timestamp"
android:textSize="@dimen/feed_item_timestamp"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/pad_5dp"
android:layout_marginLeft="@dimen/pad_5dp"
android:layout_marginRight="@dimen/pad_5dp">
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/awesomeButton"
android:layout_marginRight="8dp"
android:background="@drawable/awesome_button_2"/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/facebookSharePost"
android:layout_marginRight="8dp"
android:background="@drawable/facebook_icon"
/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/whatsApp"
android:background="@drawable/whats_app_icon"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:layout_marginRight="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report"/>
<Button
android:layout_marginRight="6dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/report"
android:background="@drawable/report_empty" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
猜猜你做错了什么:
- 您正在使用
wrap_content.
Fresco 不支持此功能,除非您还提供fresco:viewAspectRatio.
请参阅 guide to Drawees and the longer explanation 关于 wrap_content。 - 您正在使用
android:scaleType
。这对 SimpleDraweeViews 没有影响。您需要使用fresco:actualImageScaleType
。还要确保fitXY
确实是您想要的;这不会保留纵横比。请参阅 scale types. 上的文档