【发布时间】:2017-06-13 15:36:16
【问题描述】:
我有一个包含回收视图的片段,并且在每个项目上按另一个片段显示持有一个视图寻呼机,每次滑动都会显示片段。当我按下回收视图项后第一次进入片段时,寻呼机不可见。 在第二次和其余时间,数据按预期显示。
代码:
主片段包含视图寻呼机:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lineItems"
style="@style/TitleTextView"/>
<android.support.v4.view.ViewPager
android:id="@+id/CardTablepager"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"/>
</LinearLayout>
内容片段(查看寻呼机滑动此片段):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/poMainlayout">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardViewStyle"
android:layout_margin="8dp"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/poLineItemsTable"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideInset"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
我在没有帮助的情况下阅读了几篇文章:Android Viewpager display wrong data on first load
我还尝试在没有帮助的情况下使主片段中的适配器无效:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewPager.getAdapter().notifyDataSetChanged();
}
有什么想法吗?
【问题讨论】:
-
你不必把
Recyclerview放在ScrollView里面,它实现了ScrollingView&NestedScrollingChild -
我想用水平和垂直滚动创建回收视图,这不是问题,所以我更新了问题。
标签: android