【问题标题】:Viewstub above a viewpager ()一个viewpager()上面的viewstub
【发布时间】:2014-03-21 15:57:51
【问题描述】:

我有一个包含 4 个 SherlockFragment 的 viewpager(带有 actionbar sherlock),都在一个 SherlockFragmentActivity 中。

每个选项卡都有自己的 backStack(我可以在每个 SherlockFragment 上堆叠多个片段)

我想要做的是当我在列表中选择一个项目时,我想让 ViewStub(它是一个播放器)可见

我的问题是 ViewPager 不会自行调整。播放器变得可见,但在 viewpager 后面。

这是 主要的 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);
    }
}

【问题讨论】:

    标签: android view android-viewpager layout-inflater viewstub


    【解决方案1】:

    尝试 LinearLayout 垂直而不是 RelativeLayout 并将最小/最大高度设置为视图。

    想了解更多布局差异,文章是here

    【讨论】:

    • 我放弃了使用viewstub的想法。线性布局不允许调整视图的大小以填充具有固定大小(但可见/消失)的其他两个视图之间的空间。而且我不想以编程方式进行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 2012-06-06
    • 2014-03-07
    • 1970-01-01
    相关资源
    最近更新 更多