2013-08-23 112 views
1

我有我想要使用滾動視圖的佈局。滾動視圖內有ia listview有固定的9個項目,所以我希望這9個項目應顯示在完整的頁面上,其餘部分部件進入滾動視圖。滾動不工作對我的ListView

我的XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/headerLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/top_bg" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/back_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="5dp" 
      android:onClick="goBack" 
      android:src="@drawable/back_button" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="75dp" 
      android:layout_marginTop="10dp" 
      android:text="Traveller Details" 
      android:textColor="@android:color/white" /> 
    </LinearLayout> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_gravity="center" 
     android:layout_below="@+id/headerLayout" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
    <LinearLayout 
     android:id="@+id/tittleLayout" 

     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_marginTop="5dp" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/TittleTravellerDetails" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="5dp" 
      android:gravity="left" 
      android:text="Traveller Details" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="2dip" 
      android:layout_marginTop="2dp" 
      android:background="#FF909090" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/passengerDetails" 
     android:layout_below="@+id/tittleLayout" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:orientation="vertical"> 

     <Spinner 
      android:id="@+id/Tittle" 
      android:layout_width="290dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="5dp" 
      android:visibility="gone" 
      android:layout_height="wrap_content"/> 
     <EditText 
      android:id="@+id/firstName" 
      android:layout_width="290dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="10dp" 
      android:maxLines="1" 
      android:hint="First Name" /> 

     <EditText 
      android:id="@+id/LastName" 
      android:layout_width="290dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="10dp" 
      android:maxLines="1" 
      android:hint="Last Name" /> 

     <ListView 
      android:id="@+id/passengerList" 
      android:layout_width="290dp" 
      android:layout_height="166dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="10dp" 
      android:visibility="gone" 
      android:choiceMode="singleChoice" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/ContactDetailsLayout" 
     android:layout_below="@+id/passengerDetails" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_marginTop="10dp" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/TittleContactDetails" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:text="ContactDetails" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="2dip" 
      android:layout_marginTop="2dp" 
      android:background="#FF909090" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/mobileEmailDetails" 
     android:layout_below="@+id/ContactDetailsLayout" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:orientation="vertical"> 

     <EditText 
      android:id="@+id/mobileNumber" 
      android:layout_width="290dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="10dp" 
      android:maxLength="10" 
      android:maxLines="1" 
      android:inputType="number" 
      android:hint="Mobile No" /> 

     <TextView 
      android:id="@+id/emailid" 
      android:layout_width="284dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:layout_marginTop="10dp" 
      android:hint="Email ID" /> 

    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/continueBooking" 
     android:layout_below="@+id/mobileEmailDetails" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/continuebooking" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="20dp" 
      android:layout_marginTop="30dp" 
      android:src="@drawable/searchflight" /> 

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

當列表視圖將出現在佈局ID內:passengerDetails然後在編輯文本和微調將不會出現。請幫我解決issue.suggest我要做的事

+1

你永遠不應該把列表視圖下scorllview – Raghunandan

+0

你沒有得到任何異常,b'coz據我所知'ScrollView'只能有一個孩子,... – CRUSADER

+0

@Raghunandan但要求是一樣的東西,我必須這樣做 – Developer

回答

1

http://developer.android.com/reference/android/widget/ScrollView.html

從文檔

引用你不應該使用滾動型有一個ListView,因爲ListView控件需要其自身的垂直滾動的照顧。最重要的是,這樣做會挫敗ListView中用於處理大型列表的所有重要優化,因爲它有效地強制ListView顯示其整個項目列表以填充由ScrollView提供的無限容器。

您可以將您的其他視圖作爲頁眉和頁腳添加到列表視圖中。

要添加頁腳

public void addFooterView (View v)

Added in API level 1 
Add a fixed view to appear at the bottom of the list. If addFooterView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want. 

NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views. 

Parameters 
v The view to add. 

要添加頁眉

public void addHeaderView (View v)

Added in API level 1 
Add a fixed view to appear at the top of the list. If addHeaderView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want. 

NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views. 

Parameters 
v The view to add. 
+0

接受你的答案.so我怎麼能得到我的功能,我想 – Developer

+0

@Gaurav你可以添加頁眉和頁腳listview沒有你看到我以前的評論檢查編輯後。您應該發佈快照而不是要求其他人安裝其他應用來理解您的問題。如果是這種情況,向該應用程序的開發人員發送郵件可能是他會幫助您 – Raghunandan

+0

@Gaurav您在評論部分提出了太多問題。如果您有疑問與此處相關的不同,請發佈一個新問題。這引發了一場討論。如果答案有助於接受並提出一個新的問題與相關的詳細信息 – Raghunandan

0

將一個滾動條放入另一個滾動條並不是一個好主意。您需要避免這種類型的佈局構造。你可能想重新考慮你的佈局。

+0

我必須顯示列表視圖中的9個項目和高度將填充parent.s一些其他方式來創建相同的佈局 – Developer

0

這只是簡單替換以下上面滾動型:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/headerLayout" 
    android:layout_gravity="center" 
    android:fillViewport="true" >