我有一个带有Imageview的RelativeLayout。单击ImageView时,我需要调用Async任务来获取一些数据并将其显示在RecyclerView的屏幕底部。像这样:
在之前,点击任何内容:
单击ImageView-> (调用异步任务并显示进度栏):
结果:
我可以使用初始布局(第一个图像),但是我不确定如何重新组织布局以使整个事情在单击时发生。我还需要能够增加RecyclerView,因为我将允许用户在该底部加载更多“评论”。
我现在拥有的简化布局基本上是这样:
<!--Does all of this belong in a ScrollView to allow for the comments section at the bottom? -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Lots of TextViews and buttons-->
<ImageView
android:id="@+id/main_picture_with_unknown_size"
android:layout_width="match_parent"
android:layout_height="wrap_content/>
<ImageView
android:id="@+id/button_comments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_comments" />
<!-- Do I need to put the comments section here in a FrameLayout?-->
</RelativeLayout>
我在imageview上有一个单击侦听器,我想将其用作注释部分的触发器。如何在点击时展开/加载视图?
答案 0 :(得分:0)
您可以这样做:
android:visibility="gone"
隐藏。adapter.notifyDataSetChanged();
,即可通知适配器使用新数据刷新自身。现在您具有完整的回收者视图。您可以设置recyclerView.setVisibility(true);
要实现无限滚动,您可以执行以下操作:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (layoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1) {
// LOAD MORE COMMENTS AND ADD GIVE THEM TO YOUR ADAPTER
}
}
});
希望有道理。