Android FrameLayouts 并排与独立的内部滚动

标签 android android-layout android-fragments scrollview

我正在尝试设置一个平板电脑布局,左侧是一个列表,右侧是一个详细信息 Pane 。单击列表项时,详细信息 Pane 将填充一系列比左侧列表更长的卡片。我希望详细信息 Pane 和列表(回收站 View )独立滚动,但我不知道如何做到这一点。

这是我的 main_content.axml——recyclerview 被加载到 framelayout listcontainer 中,细节被放入 detailscontainer(在这发生之前,textview 被删除)——但是两个框架仍然“作为一个”滚动——整个应用程序滚动,框架不会单独滚动。

顺便说一句,main_content.xml 被包裹在一个 nestedscrollview 中,这样我就可以使用折叠工具栏 - 你可以在这里看到 main.xml:http://pastebin.com/raw/PGsVuAp6

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

  <ScrollView
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_weight="1">
      <FrameLayout
          android:id="@+id/listcontainer"
          android:layout_weight="1"
          android:layout_width="450dp"
          android:layout_height="match_parent" >
      </FrameLayout>
  </ScrollView>

  <View android:layout_height="fill_parent"
    android:layout_width="1dp"
    android:background="?android:attr/listDivider"/>

  <ScrollView
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_weight="2">
    <FrameLayout
          android:id="@+id/detailscontainer"
          android:layout_width="match_parent"
          android:layout_weight="2"
          android:layout_height="match_parent" >
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:id="@+id/nodetails"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:text="No inspection selected."/>

    </FrameLayout>
  </ScrollView>

</LinearLayout>

编辑,为清楚起见,这是加载到列表框中的内容:http://pastebin.com/raw/1Wm8Tntf ----- 这是加载到详细信息 Pane 中的内容:http://pastebin.com/raw/FetE8JP1

编辑 2:这是一张图片,显示列表和详细信息这两个框架应该如何独立滚动,即当您滚动详细信息时,列表不应移动,而当您滚动列表时,详细信息不应该移动:

enter image description here

最佳答案

ScrollView 的子级中使用 LinearLayout 而不是 FrameLayout,它会起作用!或者在 ScrollView

中尝试 android:fillViewport="true"

enter image description here

示例 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ScrollView
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_weight="1">
        <LinearLayout
            android:orientation="vertical"
            android:id="@+id/listcontainer"
            android:layout_weight="1"
            android:layout_width="450dp"
            android:layout_height="match_parent" >
            <LinearLayout
                android:background="#897"
                android:layout_width="match_parent"
                android:layout_height="300dp"></LinearLayout>
            <LinearLayout
                android:background="#127"
                android:layout_width="match_parent"
                android:layout_height="300dp"></LinearLayout>
            <LinearLayout
                android:background="#908"
                android:layout_width="match_parent"
                android:layout_height="300dp"></LinearLayout>
        </LinearLayout>
    </ScrollView>

    <View android:layout_height="fill_parent"
        android:layout_width="1dp"
        android:background="?android:attr/listDivider"/>

    <ScrollView
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_weight="2">
        <LinearLayout
            android:orientation="vertical"
            android:id="@+id/listcontainerTwo"
            android:layout_weight="1"
            android:layout_width="450dp"
            android:layout_height="match_parent" >
            <LinearLayout
                android:background="#897"
                android:layout_width="match_parent"
                android:layout_height="300dp"></LinearLayout>
            <LinearLayout
                android:background="#127"
                android:layout_width="match_parent"
                android:layout_height="300dp"></LinearLayout>
            <LinearLayout
                android:background="#908"
                android:layout_width="match_parent"
                android:layout_height="300dp"></LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

FrameLayout 只是一个容器,如果您使用 LinearLayout 无论如何它都会滚动,那么在 ScrollView 场景中大部分时间都会出现问题我已经测试过了。你可以找到笑脸问题> here

关于Android FrameLayouts 并排与独立的内部滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42001333/

相关文章:

java - 是否可以使用条件定义添加 @Override 关键字(我的意思是仅在某些 API 版本上)

android - 外部库中的自定义 View 类不起作用

android - 如何删除出现在 XML Android 列表项之间的透明线

java - 需要添加 float 操作按钮错误android中fragment页面中的多个根标签

java - 如何知道 Google Play 游戏何时连接成功?

android - 本地 gradle 仓库镜像

android - 如何从 Glide 获取图像的宽度和高度

java - Android - 需要帮助来设计具有表格布局或 ListView 的屏幕

java - 带有选项卡的 Activity 中的布局刷新问题

android - 使用 Material Design 主题时如何自定义 TextInputLayout?