繁体   English   中英

使android listview布局可滚动

[英]Making android listview layout scrollable

我有一个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以上时,我在显示布局时遇到问题。 如何使用正在显示的ListView使ImageView和TextView可滚动? 此时,只有要滚动的ListView,我希望整个布局可以滚动,就像它们本身就是一个页​​面一样。

我怎样才能做到这一点?

您可以使用<ScrollView>作为布局容器

沿着这条线的东西

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

我们内部需要LinearLayout的原因是ScrollView只能有一个直接子项

ListView具有addtoHeader和addtoFooter功能。 创建一个单独的布局并将其添加到ListView的标题中。 在您的情况下,进行imageview和textview的相对布局,并将其添加到listview的标题中。 整个页面将开始滚动。

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