简体   繁体   English

使android listview布局可滚动

[英]Making android listview layout scrollable

I have an xml file that has the layout in ASCII form: 我有一个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>

I'm having a problem displaying the layout when my ImageView and TextView takes up more than 3/4 of the screen. 当我的ImageView和TextView占据屏幕的3/4以上时,我在显示布局时遇到问题。 How do I make ImageView and TextView scrollable with the ListView that is being displayed? 如何使用正在显示的ListView使ImageView和TextView可滚动? At this point of time, only the ListView to be scrolled and I want the entire layout to be scrollable as though they are one page on its own. 此时,只有要滚动的ListView,我希望整个布局可以滚动,就像它们本身就是一个页​​面一样。

How can I do that? 我怎样才能做到这一点?

You can use <ScrollView> as your layout container 您可以使用<ScrollView>作为布局容器

something along the line of 沿着这条线的东西

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

the reason why we need the LinearLayout inside is that ScrollView can only have one direct child 我们内部需要LinearLayout的原因是ScrollView只能有一个直接子项

ListView has addtoHeader and addtoFooter function. ListView具有addtoHeader和addtoFooter功能。 Make a separate layout and add it into header of ListView . 创建一个单独的布局并将其添加到ListView的标题中。 In your case make a relative layout of imageview and textview and add it to the header of listview. 在您的情况下,进行imageview和textview的相对布局,并将其添加到listview的标题中。 The entire page will start scrolling. 整个页面将开始滚动。

Butter to use two LinearLayout with layoutweight="1" and put ScrollView in one and listview in other Butter使用两个LinearLayout和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>

如何将ImageView和TextView放在布局中并将此布局放在ScrollView中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM