我有一个 viewpager(带有操作栏 sherlock),其中包含 4 个 SherlockFragment,全部位于 SherlockFragmentActivity 内。
每个选项卡都有自己的 backStack(我可以在每个 SherlockFragment 上堆叠多个 fragment )
我想做的是当我选择列表中的一个项目时,我想让 ViewStub (它是一个播放器)可见
我的问题是 ViewPager 不会自行重新调整。播放器变得可见,但位于 View 页面后面。
这是主要的 SherlockFragmentActivity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/ActivityDark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context=".ActivityMain" >
<ViewStub
android:id="@+id/main_stubplayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:inflatedId="@+id/fragment_allzic_player"
android:layout="@layout/view_player" />
<android.support.v4.view.ViewPager
android:id="@+id/main_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/main_stubplayer" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
这是ViewStub:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/banner_player_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/cell_height"
android:background="@color/clr_player"
android:clickable="true" >
[...the content does not matter the height is fixe]
</RelativeLayout>
这是我如何使可见:
public void showPlayerBanner(String title) {
if (mViewPlayer == null) {
ViewStub stub = (ViewStub) findViewById(R.id.main_stubplayer);
mViewPlayer = stub.inflate();
} else {
mViewPlayer.setVisibility(View.VISIBLE);
}
}
最佳答案
尝试 LinearLayout 垂直而不是relativelayout 并将最小/最大高度设置为 View stub 。
要了解有关布局差异的更多信息,文章为 here
关于android - viewpager 上方的 Viewstub (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22563550/