简体   繁体   English

ScrollView不起作用

[英]ScrollView doesn't work

This is my layout: 这是我的布局:

<?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>

This is picture: 这是图片:

在此处输入图片说明

I have 4 elements on list but I can see only two and can't scroll. 我在列表上有4个元素,但是我只能看到两个并且不能滚动。 How I can do this to scroll all page not only list? 我该如何滚动所有页面而不只是列表?

You cannot have your ListView inside a ScrollView. 您不能在ScrollView中包含ListView。 Since ListView has its own implementation for Scrolling, having it inside of a ScrollView will affect its Scroll as well as your ScrollView. 由于ListView具有其自己的滚动实现,因此将其包含在ScrollView中将影响其Scroll和ScrollView。 So replace your layout in such a way that you don't have your ListView inside the 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>

In this case I put listView inside linearlayout and this solve my problem. 在这种情况下,我将listView放在linearlayout内,这解决了我的问题。

Its not a better implementation to add your listview inside a scrollview. 将您的列表视图添加到滚动视图中不是更好的实现。 when you have a listview within the scrollview and when you scroll the listview its very difficult for android to make difference and the scroll will be consumed by the scrollview though you scroll the listview and hence the items in your listview wont be lifted up. 当您在滚动视图中有一个列表视图时,当您滚动列表视图时,它很难使Android发挥作用,尽管滚动列表视图时滚动视图仍会占用滚动视图,因此列表视图中的项目不会被抬起。 So you replace your scroll view by Linear layout. 因此,您可以将滚动视图替换为线性布局。

Also by looking at your layout design it can be found that many of the layouts are not really needed. 另外,通过查看布局设计,可以发现实际上并不需要很多布局。 Its better you review your design. 最好您检查一下设计。 Lint can help you out in removing the unnecessary layouts. Lint可以帮助您删除不必要的布局。

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

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