質問

I have a viewpager (with actionbar sherlock) containing 4 SherlockFragment, all inside a SherlockFragmentActivity.

Each tab has it's own backStack (i can stack several fragments ON each SherlockFragment)

What i'm trying to do is when i select an item in the list, i want to make visible a ViewStub (which is a player)

My problem is that the ViewPager Does not redim itself. The player become visible but behind the viewpager.

Here is the main 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>

Here is the 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>

Here is how i make is visible :

public void showPlayerBanner(String title) {
    if (mViewPlayer == null) {
        ViewStub stub = (ViewStub) findViewById(R.id.main_stubplayer);
        mViewPlayer = stub.inflate();
    } else {
        mViewPlayer.setVisibility(View.VISIBLE);
    }
}
役に立ちましたか?

解決

Try LinearLayout vertical instead of RelativeLayout and set the min/max height to the viewstub.

To know more about the layout differences, the article is here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top