2012-05-16 50 views
1

這是我的佈局:滾動型不起作用

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

這是圖片:

enter image description here

我對清單4組的元素,但我只能看到兩個不能滾動。我如何做到這一點,滾動所有頁面不僅列表?

回答

2
 <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,這解決了我的問題。

2

你不能讓你的ListView在一個ScrollView中。由於ListView有自己的Scrolling實現,所以在ScrollView中它會影響它的Scroll和ScrollView。因此,以這種方式替換您的佈局,使得您在ScrollView中沒有ListView。

+0

但是當我在scrollView的外面放置listView時,一部分頁面會滾動,而listView有我們的滾動。我希望所有頁面都可以滾動。 – edi233

+0

是的,我知道這真令人沮喪。您可以簡單地使用表格佈局併爲其添加動態視圖。它並不難做到。試着讓我知道。但這是唯一的方法,而不需要改變你的屏幕設計。 –

+0

好的,我解決了我的問題,但其他方式。我的列表視圖放在線性佈局裏面,它完美的工作。 Thx尋求建議和幫助。 – edi233

1

它不是一個更好的實現在滾動視圖中添加你的列表視圖。當你在scrollview中有一個listview,並且當你滾動listview時,它很難讓android有所作爲,滾動視圖將會消耗滾動,儘管你滾動listview,因此listview中的項目不會被提升。所以你用線性佈局替換你的滾動視圖。

通過查看您的佈局設計,可以發現很多佈局並不是真的需要。它更好地審查你的設計。林特可以幫助你消除不必要的佈局。