繁体   English   中英

ScrollView不起作用

[英]ScrollView doesn't work

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
        <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/scrollViewContact"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:fillViewport="true">
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:id="@+id/contactOuterLayout"
    >

    <RelativeLayout 
        android:layout_height="fill_parent"
        android:id="@+id/contactOuterRelativeLayout" 
        android:layout_width="fill_parent"
        android:background="@drawable/radialback">



            <RelativeLayout android:id="@+id/relativeLayout1"
                android:layout_height="wrap_content"                     
                android:layout_width="fill_parent"
                android:layout_below="@+id/tableLayout1" 
                android:paddingBottom="10sp">

                <TableLayout
                    android:id="@+id/contactdetails"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:stretchColumns="*" >

                    <TableRow 
                        android:id="@+id/mapView"
                        android:layout_height="wrap_content"
                        android:layout_width="fill_parent"
                        >
                        <LinearLayout 
                            android:id="@+id/liny"
                            android:layout_height="match_parent"
                            android:layout_width="match_parent"
                            android:orientation="horizontal"
                            android:weightSum="100">

                            <com.google.android.maps.MapView
                                 android:id="@+id/map"
                                 android:layout_height="100dp"
                                 android:layout_width="100dp"
                                 android:layout_marginLeft="20dp"
                                 android:layout_marginTop="15dp"
                                 android:enabled="true"
                                 android:clickable="true"
                                 android:apiKey="00n1pmS8eEhXhD5a6Q3UTDd6zortw9t4l_jXioQ"
                                />

                <TextView
                    android:id="@+id/MapAdrress"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginTop="15dp"
                    android:layout_weight="30"
                    android:text="TextView" />

                        </LinearLayout>

                    </TableRow>


                    <TableRow android:layout_width="fill_parent"
                        android:layout_height="wrap_content">



                        <TableLayout android:id="@+id/contactinfo" 
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            >



                            <TableRow android:layout_width="fill_parent"
                                android:layout_height="wrap_content">
                                <TableLayout android:id="@+id/contactinfo2" 
                                    android:layout_width="fill_parent"
                                    android:layout_height="wrap_content">
                                    <!-- Telephone number, web-site etc -->         
                                </TableLayout>                                                                      
                            </TableRow> 



                    </TableLayout>              

                    </TableRow> 

                    <TableRow android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center">

                        <TableLayout android:id="@+id/contactinfo" 
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"

                            >

                        <Button
                            android:id="@+id/butonek"
                            android:layout_width="10dp"
                            android:layout_height="wrap_content"
                             />

                    </TableLayout>

                    </TableRow>


                    <TableRow android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:paddingTop="20dip">
                        <TableLayout android:layout_width="fill_parent"
                            android:layout_height="wrap_content">                                   
                            <TableRow android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center"
                                android:gravity="center_horizontal">
                                <TableLayout android:id="@+id/address" 
                                    android:layout_width="200dip"
                                    android:layout_height="wrap_content">
                                    <!-- Address -->
                                </TableLayout>
                            </TableRow>
                        </TableLayout>
                    </TableRow>                     
                    <TableRow android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:paddingTop="20dip">
                                        <ListView
                     android:id="@+id/contactlist"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent" 
                     android:choiceMode="multipleChoice"
                     />

                    </TableRow> 
                </TableLayout>
            </RelativeLayout>

    </RelativeLayout>
</LinearLayout>
    </ScrollView>

这是图片:

在此处输入图片说明

我在列表上有4个元素,但是我只能看到两个并且不能滚动。 我该如何滚动所有页面而不只是列表?

您不能在ScrollView中包含ListView。 由于ListView具有其自己的滚动实现,因此将其包含在ScrollView中将影响其Scroll和ScrollView。 因此,以一种不在ScrollView内的ListView的方式替换布局。

        <LinearLayout 
        android:layout_height="match_parent"
        android:layout_width="match_parent">
            <ListView
                 android:id="@+id/contactlist"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent" 
                 android:choiceMode="multipleChoice"
                 />
                 </LinearLayout>

在这种情况下,我将listView放在linearlayout内,这解决了我的问题。

将您的列表视图添加到滚动视图中不是更好的实现。 当您在滚动视图中有一个列表视图时,当您滚动列表视图时,它很难使Android发挥作用,尽管滚动列表视图时滚动视图仍会占用滚动视图,因此列表视图中的项目不会被抬起。 因此,您可以将滚动视图替换为线性布局。

另外,通过查看布局设计,可以发现实际上并不需要很多布局。 最好您检查一下设计。 Lint可以帮助您删除不必要的布局。

暂无
暂无

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

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