Android中scrollview下方的ListView

Android中scrollview下方的ListView,android,android-layout,Android,Android Layout,我试图在android中的滚动视图下放置列表视图。我试着像这样把它们放在一个线性布局中 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/frameLayout" android:layout_width="fill_parent" android:la

我试图在android中的
滚动视图下放置
列表视图
。我试着像这样把它们放在一个
线性布局中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/frameLayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <ScrollView 
      android:id="@+id/marketDetailScrollView"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" >
   ...
  </ScrollView>
  <ListView  android:id="@android:id/list" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    android:background="#FFF"/>
</LinearLayout>

...
列表视图
不会显示。我还试着把它放在一个
RelaviteLayout
中,但还是什么都没有。我是否可以在
滚动视图
下使用
列表视图


只是想补充一点。我不想分割我的屏幕,这样我就有一个带有
滚动视图的一半,另一个带有
列表视图的一半。我希望用户向下滚动
滚动视图
,它明显大于屏幕大小,然后
列表视图
应该开始

填充父视图
对您不起作用,
将其更改为“包装内容”,并为“滚动视图”赋予布局权重1,这样可能对您有用

通常将listview置于“滚动视图”中并不好。但如果需要,则需要设置listview的高度。按照下面的链接计算在scrollview中安装的listview的高度


使用这种方法,您可以实现您想要的

您必须将scrollview的内容高度及其元素设置为“包装内容”。XML将如下所示:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView 
  android:id="@+id/marketDetailScrollView"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" >
...(height will be wrap_content for inner element as well)
</ScrollView>
<ListView  android:id="@android:id/list" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"
android:background="#FFF"
android:layout_weight="1"/>
</LinearLayout>

…(高度也将是内部元素的包裹内容)

这可能会对你有所帮助。

我想这与你想要的差不多。我给你这个代码,但我必须告诉你,把
列表视图
放在
滚动视图
中是一个不好的做法,你不应该使用这个解决方案。您应该在scroll view中没有滚动视图的情况下处理更正确的内容

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:id="@+id/containerScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/scrollViewContent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/marketDetailScrollView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/scrollViewContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <!-- the views contained in your ScrollView goes here -->
            </LinearLayout>
        </ScrollView>

        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFF" />
    </LinearLayout>

</ScrollView>

我建议您将ScrollView内容作为HeaderView放在ListView中,还是明确希望在屏幕上有两个单独的可滚动区域

将滚动视图的内容作为标题放在列表视图中的示例(一个可滚动区域):

public void onCreate(Bundle s){
    setContentView(R.id.yourLayout);

    ListView listView = (ListView) findViewById(R.id.listView);

    // Set the adapter before the header, because older 
    // Android version may have problems if not

    listView.setAdapter(new YourAdapter());

    // Add the header
    View header = inflater.inflate(
            R.layout.you_layout_that_was_in_scrollview_before, null, false); 

    listView.addHeaderView(header);

}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView 
  android:id="@+id/marketDetailScrollView"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1" >
  <!-- ScrollViewContent -->
</ScrollView>
<ListView  android:id="@android:id/list" 
android:layout_height="0dp" 
android:layout_width="match_parent"
android:background="#FFF"
android:layout_weight="1"/>
</LinearLayout>
活动的布局如下所示:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView  android:id="@+id/listView" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"
    android:background="#FFF"/>
</LinearLayout>

如果需要两个可滚动区域,则应使用布局权重:

public void onCreate(Bundle s){
    setContentView(R.id.yourLayout);

    ListView listView = (ListView) findViewById(R.id.listView);

    // Set the adapter before the header, because older 
    // Android version may have problems if not

    listView.setAdapter(new YourAdapter());

    // Add the header
    View header = inflater.inflate(
            R.layout.you_layout_that_was_in_scrollview_before, null, false); 

    listView.addHeaderView(header);

}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView 
  android:id="@+id/marketDetailScrollView"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1" >
  <!-- ScrollViewContent -->
</ScrollView>
<ListView  android:id="@android:id/list" 
android:layout_height="0dp" 
android:layout_width="match_parent"
android:background="#FFF"
android:layout_weight="1"/>
</LinearLayout>


固定滚动视图的高度。。像
android:layout\u height=“100dip”
一样,您可以让listview将scrollview中的视图作为页眉或页脚添加到listview(不带scrollview),或者指定滚动视图的固定高度,并在滚动视图的下方添加listview,
android:layou height=“fill\u parent”
意味着您的scrollview将占据底部的所有空间,因此ListView没有更多空间。您正在使用
LinearLayout
,并将
ListView
放在
scrollview
下面,另外,您还可以设置
滚动视图的
宽度
高度
填充父视图
,这样
滚动视图
将覆盖并获得
列表视图
的显示,如果您希望显示
列表视图
,请为
滚动视图
设置特定的大小,例如,
200dp
。希望这有帮助。它不在滚动视图中,它在滚动视图下。哦,好的。在这种情况下,只需使用weight属性并在linearlayout中设置scrollview和listview的权重。这可能是因为您的ScrollView的内部内容。你能告诉我scrollView的内部内容是什么吗?内部内容与此有什么关系?scrollview大于屏幕检查内容的高度是否为fill\u parent/match parent。我的代码运行良好。只需检查它是否工作。当你发布答案时,会通知OP。。。每次你回答问题时,不需要在问题下发表评论……不,我不需要。所以通过将is作为headerview来创建一个可滚动的视图?是的。。。这将创建一个可滚动的区域。。。我将更新我的答案,并添加一个示例。在标题导致android崩溃之前,我仍有两个可滚动区域正在设置适配器。除了这一部分,这很好。它取决于Android API。我想,安卓4.1已经改变了这一点。我不记得正确的方法是什么,但是如果它在设置适配器后崩溃,那么在将适配器设置到listview之前设置它,反之亦然。我想在将适配器设置为列表视图之前设置标题应该适用于所有android平台。