2013-08-05 24 views
0

我在Android中有兩個主要視圖:帶有一些文本框的頁眉佈局以及視圖組,它是不等高度元素網格的自己實現。正如你可以在圖片中看到:滾動Android中活動中的所有元素

enter image description here

我想能夠滾動不僅在視圖中的元素,但整個活動。我不能使用setHeaderView作爲列表,因爲它不是ListView,它是ViewGroup的子類。我不能夠實現這種:-(

這裏是代碼我想使用:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#E0E0DE" 
    tools:context=".MainActivity" > 

    <include 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     layout="@layout/layout_action_bar" /> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingBottom="@dimen/activity_vertical_margin" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" > 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="200dp" > 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:src="@drawable/background" 
        android:scaleType="centerCrop" 
        android:adjustViewBounds="true" /> 

       <include 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        layout="@layout/layout_search_view" 
        android:layout_centerInParent="true" 
        android:layout_marginLeft="20dp" 
        android:layout_marginRight="20dp" /> 

      </RelativeLayout> 

      <include 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       layout="@layout/layout_location_info" /> 

      <com.tenea.turipolis.UnequalGridView 
       android:id="@+id/listPictures" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical" 
       android:columnCount="2" 
       android:padding="2dp" 
       android:verticalSpacing="2dp" 
       android:horizontalSpacing="2dp" /> 

     </LinearLayout> 

    </ScrollView> 

</LinearLayout> 

感謝您的支持,

回答

2

ScrollView環繞你的整個佈局

+0

感謝您的評論。 「ScrollViews只能有一個子部件,如果你想要更多的孩子,可以將它們包裝在一個容器佈局中。」 –

+0

將當前使用的佈局僅用作ScrollView的子項。這就是我所說的「圍繞你的整個佈局」。 – dst

+0

嗨dst,這是不夠的,因爲我需要拉伸ViewGroup。我怎樣才能做到這一點,以便能夠滾動到ViewGroup的結尾? –

0

裹在你的佈局:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

// your layout here 

</ScollView> 

你只能有一個兒童部件,例如:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    // your layout here 

    </LinearLayout> 

</ScollView> 
+0

嗨喬,感謝您的評論。它的作品,但它不是我嘗試做的。最後一點是我需要將ViewGroup拉伸到最後才能夠滾動整個列表。我的意思是,用你的方法我可以滾動,但我需要修復ViewGroup的高度。 –

+0

不是100%你需要什麼,沒有看到你所有的代碼都很難。嘗試將線性佈局中的layout_height更改爲「fill_parent」?也許其他觀點也需要這樣設置? –

+0

不是100%肯定* –