Java 使android listview布局可滚动

Java 使android listview布局可滚动,java,android,user-interface,listview,layout,Java,Android,User Interface,Listview,Layout,我有一个xml文件,其布局为ASCII格式: --------------- | ImageView -------------- | TextView -------------- | List... -------------- <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp

我有一个xml文件,其布局为ASCII格式:

---------------
| ImageView
--------------
| TextView
--------------
| List...
--------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.some.app"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<ImageView 
android:id="@+id/MovieCover"
android:layout_width="100dip"
android:layout_height="100dip"
/> 
 <TextView
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textSize="16sp"
    android:padding="10dp"
    android:id="@+id/TextHeader"
    android:background="#000000">
</TextView>
<ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
 android:layout_width="fill_parent">
 </ListView>
 </LinearLayout>
---------------
|图像视图
--------------
|文本视图
--------------
|列表。。。
--------------
当ImageView和TextView占据屏幕的3/4以上时,我在显示布局时遇到问题。如何使ImageView和TextView与正在显示的ListView一起滚动?此时,只需滚动ListView,我希望整个布局可以滚动,就好像它们本身就是一个页面一样

我该怎么做呢?

您可以使用
作为布局容器

类似于

<ScrollView>
    <LinearLayout>
    // your layout here
    </LinearLayout>
</ScrollView>

//你的布局在这里

我们需要内部线性布局的原因是ScrollView只能有一个直接子项,将ImageView和TextView放在一个布局中,将此布局放在ScrollView中如何?

使用两个带有
layoutweight=“1”
的线性布局,将ScrollView放在一个布局中,将listview放在另一个布局中

<LinearLayout android:layout_weight="1"
        android:layout_height="fill_parent" android:layout_width="fill_parent">
        <ScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"            
                                android:layout_height="fill_parent">

                          <!-- scroll view content -->
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
    <LinearLayout android:layout_weight="1"
        android:layout_height="fill_parent" android:layout_width="fill_parent">
        <ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
            android:layout_width="fill_parent">
        </ListView>
    </LinearLayout>


列表视图具有addtoHeader和addtoFooter功能。制作一个单独的布局并将其添加到ListView的标题中。在本例中,创建imageview和textview的相对布局,并将其添加到listview的标题中。整个页面将开始滚动。

理想情况下,将整个布局放在滚动视图中应该可以工作,但android指南说不要将ListView放在滚动视图中,好奇地想知道解决方案,因此投票赞成!