gpt4 book ai didi

android - 在类似于 Facebook 时间线的回收站 View 中显示图像

转载 作者:行者123 更新时间:2023-11-30 01:44:03 25 4
gpt4 key购买 nike

我正在创建一个 Android 应用程序,我卡在了某个点上。我想在 Facebook 时间轴中显示帖子。帖子可能有图片,也可能没有。我为其他帖子元素创建了一个卡片 View ,我可以在帖子中显示它们。我有从服务器发送的帖子图像的图像链接,现在我想下载图像并显示在其中有图像的特定帖子上。我怎样才能做到这一点?如果用户有 10 个帖子,则可能有一个或两个图像。如何检查哪个帖子有图片,然后在下载后在该帖子中显示图片。任何人都可以帮助我吗?

如果您需要更多信息,请告诉我。我的卡片 View 如下图所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/imageViewUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/human_image"/>

<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imageViewUser"
android:layout_toEndOf="@+id/imageViewUser"
android:textSize="18sp"
android:text="titleText"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"/>

<TextView
android:id="@+id/textViewNoOfDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewTitle"
android:textSize="14sp"
android:layout_marginLeft="10dp"
android:text="No of Days"
android:layout_toRightOf="@+id/imageViewUser"
android:layout_alignBottom="@+id/imageViewUser"/>

<TextView
android:id="@+id/textViewPostDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageViewUser"
android:layout_marginTop="20dp"
android:text="ABCDE"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"/>

<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#c0c0c0"
android:layout_below="@+id/postImage"
android:layout_marginTop="10dp"/>

<ImageButton
android:id="@+id/imageButtonPin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@mipmap/ic_pin_grey600_18dp"/>

<ImageView
android:id="@+id/postImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewPostDescription"
/>








</RelativeLayout>






</android.support.v7.widget.CardView>




</RelativeLayout>

最佳答案

这就是我设法让它工作的方式。

适配器类:

public class StoriesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private List<Success> successList;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
private Context mContext;

public StoriesAdapter(Context context, List<Success> successList) {
this.successList = successList;
this.mContext = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.success_list, parent, false);
StoryItemViewHolder vh = new StoryItemViewHolder(v);

return vh;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
final Success success = successList.get(position);
StoryItemViewHolder holder = (StoryItemViewHolder) viewHolder;
// Feed image
if (!success.getThumbnailUrl().equals("null")) {//check if null
holder.thumbNail.setImageUrl(success.getThumbnailUrl(), imageLoader);
holder.thumbNail.setVisibility(View.VISIBLE);
holder.thumbNail.setResponseObserver(new FeedImageView.ResponseObserver() {
@Override
public void onError() {
}

@Override
public void onSuccess() {
}
});
} else {
holder.thumbNail.setVisibility(View.GONE);
}

}
@Override
public int getItemCount() {
return (null != successList ? successList.size() : 0);
}

}

和 viewHolder:

public class StoryItemViewHolder extends RecyclerView.ViewHolder {
public FeedImageView thumbNail;

public StoryItemViewHolder(View view) {
super(view);
this.thumbNail= (FeedImageView) view.findViewById(R.id.newsImage);
}

}

关于android - 在类似于 Facebook 时间线的回收站 View 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33981505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com