1

我有布局,我想使用滚动视图。在滚动视图内部有固定 9 个项目的 ia listview,所以我希望这 9 个项目应显示在完整页面上,其余部分位于滚动视图内。

我的 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>

当 Listview 将出现在布局 id 中时:passengerDetails然后编辑文本和微调器将不会出现。请帮我解决问题。建议我该怎么做

4

3 回答 3

1

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

从文档中引用

您永远不应该将 ScrollView 与 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.
于 2013-08-23T08:14:36.220 回答
0

将一个可滚动的内容放在另一个中并不是一个好主意。您需要避免这种类型的布局构造。您可能需要重新考虑您的布局。

于 2013-08-23T07:53:41.607 回答
0

只需简单地将上面的 ScrollView 替换为以下内容:

  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/headerLayout"
    android:layout_gravity="center"
    android:fillViewport="true" >
于 2013-08-23T08:22:20.793 回答