[英]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.