我正在尝试设置一个平板电脑布局,左侧是一个列表,右侧是一个详细信息 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:这是一张图片,显示列表和详细信息这两个框架应该如何独立滚动,即当您滚动详细信息时,列表不应移动,而当您滚动列表时,详细信息不应该移动:
最佳答案
在 ScrollView
的子级中使用 LinearLayout
而不是 FrameLayout
,它会起作用!或者在 ScrollView
android:fillViewport="true"
示例 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/