0

我将 ActionBarSherlock 与 SherlockNavigationDrawer 一起使用

默认的fragment_main_layout.xml

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
     space available using match_parent in both dimensions. -->
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:scrollbarStyle="outsideOverlay">
    <TextView android:id="@+id/content_text"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:text="@string/description"
              android:textAppearance="?android:attr/textAppearanceMedium"/>
</ScrollView>
<!-- android:layout_gravity="left" tells DrawerLayout to treat
     this as a sliding drawer on the left side. The drawer is
     given a fixed width in dp and extends the full height of
     the container. A solid background is used for contrast
     with the content view. -->
<ListView android:id="@+id/left_drawer"
          android:layout_width="300dp"
          android:layout_height="match_parent"
          android:layout_gravity="left"
          android:background="@android:color/white"/>

我需要在显示 TextView 的位置放置另一个列表视图。为了让自己清楚,我需要用户按下导航抽屉,从 left_drawer 中选择一个选项,主内容窗口中将显示一个列表视图而不是文本视图。

我做了一些实验,但是它们导致与两个列表视图发生冲突(有时不填充 left_drawer 或相反,或者只显示第二个列表视图中的第一个字段)

4

1 回答 1

0

自己修好了

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
     space available using match_parent in both dimensions. -->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarStyle="outsideOverlay">
    <ListView android:id="@+id/main_content_list"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@android:color/white"/>
    <TextView android:id="@+id/content_text"
              android:paddingLeft="5dp"
              android:paddingRight="5dp"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:text="@string/description"
              android:textAppearance="?android:attr/textAppearanceMedium"/>
</RelativeLayout>
<!-- android:layout_gravity="left" tells DrawerLayout to treat
     this as a sliding drawer on the left side. The drawer is
     given a fixed width in dp and extends the full height of
     the container. A solid background is used for contrast
     with the content view. -->
<ListView android:id="@+id/left_drawer"
          android:layout_width="300dp"
          android:layout_height="match_parent"
          android:layout_gravity="left"
          android:background="@android:color/white"/>

将 ScrollView 更改为 RelativeLayout,在里面添加了新的 id:main_content_list 列表视图

于 2013-10-17T09:23:19.780 回答