0

我和SlidingPaneLayout. 我正在尝试使用 3 个面板创建活动,如图所示: 在此处输入图像描述

情况是我希望面板 2 默认可见,当用户从左向右滑动时应该打开面板 1,当从右向左滑动面板 3 时。当我将视图添加到SlidingPaneLayout最后添加时,默认情况下是可见的。有什么方法可以设置哪个视图应该是开始视图?这是我的布局xml:

<android.support.v4.widget.SlidingPaneLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/side_menu_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="@color/gray"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/oliveGreen">
    </LinearLayout>
    <ListView android:id="@+id/right_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_marginRight="0dp"
        android:layout_marginEnd="0dp"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="@color/gray"/>
</android.support.v4.widget.SlidingPaneLayout>

在此配置rightDrawer显示为起始视图。我想显示LinearLayout并设置rightDrawr在它的右侧。我希望我说清楚了,我将不胜感激。先感谢您。

4

2 回答 2

0

设置您的自定义适配器并在那里定义它。 https://github.com/survivingwithandroid/Surviving-with-android/tree/master/SlidingPaneLayout/src/com/survivingwithandroid/slidingpanelayout/adapter

于 2015-05-18T20:32:39.647 回答
0

编辑:

我刚刚重新阅读了 文档SlidingPaneLayout,似乎它仅适用于 2 个视图。

您可以尝试通过使用 a 来伪造此布局,ViewPager并使用float getPageWidth(int)来自适配器的 0 和 2 页缩小。不确定这是否符合您的要求。

除此之外,您唯一能做的就是检查SlidingPaneLayout 源代码并对其进行修改以使其left/right像抽屉一样在重力下工作。

原始答案

不确定我是否理解您的问题,也许您希望它的行为有所不同。

您只是gravity用来告诉面板将在哪一侧:

<android.support.v4.widget.SlidingPaneLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/side_menu_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   <View android:gravity="left" />
   <View android:gravity="right />
   <View  /> << that's the one always visible.

</android.support.v4.widget.SlidingPaneLayout>

像这样。

于 2015-05-18T20:32:44.857 回答