【发布时间】:2015-04-16 15:59:31
【问题描述】:
我在使用 SlidingUpPanel (https://github.com/umano/AndroidSlidingUpPanel) 和 FragmentStatePagerAdapter 时遇到问题。
我在寻呼机中有 3 个片段:前两个带有滑动面板(一个是片段,一个是硬编码布局),第三个没有。 当我有一个只有两个片段的寻呼机时,面板工作得很好。现在我添加了三分之一,它们不再工作了。
起初片段是正确创建的,但是当我一直滑动到第三个然后再回来时,面板就搞砸了。 基本上,以前在第一个片段上的面板现在在第二个片段的面板上,第二个面板的硬编码布局现在消失了,第一个片段的面板是空的。
所有片段的主要内容仍然正确并按预期运行。
为了更好地解释,我画了一个图式:
我选择片段的代码是:
public Fragment getItem(int i) {
Fragment fragment = null;
switch (i) {
case 0:
fragment = new MatchListFragment();
break;
case 1:
fragment = new StreamFragment();
break;
case 2:
fragment = new PendingMatches();
break;
default:
break;
}
return fragment;
}
第一个片段的布局(MatchListFragment):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
CONTENT
</RelativeLayout>
<FrameLayout
android:id="@+id/scrollable_panel"
android:layout_width="match_parent"
android:layout_height="match_parent" />
第二个片段(StreamFragment)的布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/log_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:divider="@drawable/material_divider"
android:dividerHeight="1dp"
android:visibility="visible" />
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scrollable_panel"
android:layout_width="match_parent"
android:layout_height="88dp"
android:background="@color/white"
android:gravity="center">
<ImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:background="@color/light_gray" />
<ImageView
android:layout_width="25dp"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:src="@drawable/green_pill" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/icon"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/profile_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_profile_icon"
app:undertext="New" />
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/talk_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_talk_icon"
app:undertext="Learning" />
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/conversation_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_conversation_icon"
app:undertext="Teaching" />
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/all_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_all_icon"
app:undertext="All" />
</LinearLayout>
</RelativeLayout>
我真的不明白如何解决这个问题,特别是因为在第二个片段 (StreamFragment()) 上,滑动面板布局是硬编码的,我不明白为什么它会正确加载其他所有内容,并将面板替换为第一个片段(MatchListFragment)。
【问题讨论】:
标签: android android-fragments fragmentstatepageradapter