如果列表包含更多数据,则在下面的幻灯片视图



我有一个列表视图,其中数据动态出现。我在某些视图下添加了ListView。我希望,如果我的列表中有数据查看,ListView下面的视图应滑下。现在,它没有滑动,我的半列表显示。

这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="65.3dp"
        android:layout_height="40.0dp"
        android:id="@+id/button_back"
        android:textColor="#ffada8a8"
        android:text="Back"
        android:drawableLeft="@drawable/Back_icon"
        android:background="#000000"
        android:layout_marginLeft="10dp" />
    <TextView
        android:text="Booking Request"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="161.3dp"
        android:layout_height="34.5dp"
        android:layout_toRightOf="@id/button_back"
        android:id="@+id/lable_booking_request"
        android:gravity="center"
        android:layout_centerHorizontal="true" />
    <Button
        android:text="Submit"
        android:layout_width="wrap_content"
        android:layout_height="34.5dp"
        android:layout_toRightOf="@id/lable_booking_request"
        android:id="@+id/button2"
        android:layout_alignParentRight="true"
        android:background="#ff000000"
        android:layout_marginRight="10dp"
        android:textColor="#ffffffff" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="45.8dp"
        android:layout_below="@id/button_back"
        android:id="@+id/view1"
        android:layout_marginTop="10dp"
        android:background="#1E1E1E" />
    <Button
        android:text="New Booking"
        android:layout_width="150dp"
        android:layout_height="37dp"
        android:layout_below="@id/view1"
        android:id="@+id/lable_new_booking"
        android:layout_marginTop="-42dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/stylenew" />
    <Button
        android:text="Current Booking"
        android:layout_width="match_parent"
        android:layout_height="37dp"
        android:layout_toRightOf="@id/lable_new_booking"
        android:id="@+id/button3"
        android:textColor="#B361B3"
        android:layout_marginRight="10dp"
        android:background="@drawable/style"
        android:layout_marginTop="55dp" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="44.0dp"
        android:layout_below="@id/view1"
        android:id="@+id/viewServiceType"
        android:background="#171717"
        android:layout_marginTop="5dp" />
    <TextView
        android:text="Select Service Type"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/view1"
        android:id="@+id/textselectuser"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp" />
    <ImageView
        android:src="@drawable/go"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/view1"
        android:id="@+id/imageView1"
        android:layout_alignParentRight="true"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="44.0dp"
        android:layout_below="@id/viewServiceType"
        android:id="@+id/view2"
        android:layout_marginTop="5dp"
        android:background="#171717" />
    <TextView
        android:text="Pick Date &amp; Time"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/viewServiceType"
        android:id="@+id/textpickDateTime"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="44dp"
        android:layout_below="@id/view2"
        android:id="@+id/view3"
        android:background="#171717"
        android:layout_marginTop="5dp" />
    <TextView
        android:text="Select User"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/view2"
        android:id="@+id/textSelectUser"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp" />
    <ListView
        android:layout_below="@id/view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listViewSaloonUser"
        android:layout_marginTop="140dp" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="44dp"
        android:layout_below="@id/listViewSaloonUser"
        android:id="@+id/view4"
        android:background="#171717" />
    <TextView
        android:text="Add/Edit Remainder"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/listViewSaloonUser"
        android:id="@+id/textView1"
        android:layout_marginTop="12dp"
        android:layout_marginLeft="10dp" />
    <RelativeLayout
        android:id="@id/layoutlinear2"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="152.0dp"
        android:layout_below="@id/view4">
        <TextView
            android:layout_width="213.3dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="10dp"
            android:text="One day before appointment"
            android:id="@+id/servicetype1"
            android:gravity="center_vertical"
            android:textSize="15dp" />
        <ImageView
            android:src="@drawable/Unchecked"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/servicetype1"
            android:id="@+id/imageView2"
            android:layout_alignParentRight="true"
            android:layout_marginTop="-23dp"
            android:layout_marginRight="20dp" />
        <View
            android:layout_width="wrap_content"
            android:layout_height="0.2dp"
            android:layout_below="@id/servicetype1"
            android:id="@+id/seperator"
            android:visibility="visible"
            android:background="@drawable/hSeparator"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp" />
        <TextView
            android:layout_width="194.7dp"
            android:layout_below="@id/seperator"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Add custom Remainder"
            android:id="@+id/servicetype2"
            android:gravity="center_vertical"
            android:textSize="15dp" />
        <ImageView
            android:src="@drawable/Unchecked"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/servicetype1"
            android:id="@+id/imageviewunchecked"
            android:layout_alignParentRight="true"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp" />
        <View
            android:layout_width="wrap_content"
            android:layout_height="0.2dp"
            android:layout_below="@id/imageviewunchecked"
            android:id="@+id/seperator2"
            android:visibility="visible"
            android:background="@drawable/hSeparator"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp" />
        <TextView
            android:layout_width="194.7dp"
            android:layout_below="@id/seperator2"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Add Remainder to calender"
            android:id="@+id/servicetype2"
            android:gravity="center_vertical"
            android:textSize="15dp" />
        <ImageView
            android:src="@drawable/add"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_below="@id/servicetype2"
            android:id="@+id/imageView3"
            android:layout_alignParentRight="true"
            android:layout_marginRight="20dp"
            android:layout_marginTop="-23dp"
            android:layout_marginBottom="23dp" />
    </RelativeLayout>
</RelativeLayout>

我想要ListView有任何数据,即具有id=@+id/view4的视图应滑到下方。

这是我的适配器代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
    android:text="Saloon User 1"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_width="249.3dp"
    android:layout_height="wrap_content"
    android:id="@+id/textViewSaloonUser"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="20dp" />
<ImageView
    android:src="@drawable/Unchecked"
    android:layout_width="40.0dp"
    android:layout_height="20.0dp"
    android:layout_toRightOf="@id/textViewSaloonUser"
    android:id="@+id/imageViewcheckbox"
    android:layout_marginRight="20dp"
    android:layout_marginTop="12dp" />
<View
    android:layout_width="wrap_content"
    android:layout_height="0.2dp"
    android:layout_below="@id/textViewSaloonUser"
    android:id="@+id/view1"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:background="@drawable/hSeparator" />

任何人都可以告诉我如何实现这一点。

您不应该在滚动视图中具有listView(两者都可以滚动)。

在您的情况下解决方案是仅使用标头和页脚使用列表视图:

创建一个布局标题。xml并提取以下内容:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="65.3dp"
        android:layout_height="40.0dp"
        android:id="@+id/button_back"
        android:textColor="#ffada8a8"
        android:text="Back"
        android:drawableLeft="@drawable/Back_icon"
        android:background="#000000"
        android:layout_marginLeft="10dp" />
    <TextView
        android:text="Booking Request"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="161.3dp"
        android:layout_height="34.5dp"
        android:layout_toRightOf="@id/button_back"
        android:id="@+id/lable_booking_request"
        android:gravity="center"
        android:layout_centerHorizontal="true" />
    <Button
        android:text="Submit"
        android:layout_width="wrap_content"
        android:layout_height="34.5dp"
        android:layout_toRightOf="@id/lable_booking_request"
        android:id="@+id/button2"
        android:layout_alignParentRight="true"
        android:background="#ff000000"
        android:layout_marginRight="10dp"
        android:textColor="#ffffffff" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="45.8dp"
        android:layout_below="@id/button_back"
        android:id="@+id/view1"
        android:layout_marginTop="10dp"
        android:background="#1E1E1E" />
    <Button
        android:text="New Booking"
        android:layout_width="150dp"
        android:layout_height="37dp"
        android:layout_below="@id/view1"
        android:id="@+id/lable_new_booking"
        android:layout_marginTop="-42dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/stylenew" />
    <Button
        android:text="Current Booking"
        android:layout_width="match_parent"
        android:layout_height="37dp"
        android:layout_toRightOf="@id/lable_new_booking"
        android:id="@+id/button3"
        android:textColor="#B361B3"
        android:layout_marginRight="10dp"
        android:background="@drawable/style"
        android:layout_marginTop="55dp" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="44.0dp"
        android:layout_below="@id/view1"
        android:id="@+id/viewServiceType"
        android:background="#171717"
        android:layout_marginTop="5dp" />
    <TextView
        android:text="Select Service Type"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/view1"
        android:id="@+id/textselectuser"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp" />
    <ImageView
        android:src="@drawable/go"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/view1"
        android:id="@+id/imageView1"
        android:layout_alignParentRight="true"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="44.0dp"
        android:layout_below="@id/viewServiceType"
        android:id="@+id/view2"
        android:layout_marginTop="5dp"
        android:background="#171717" />
    <TextView
        android:text="Pick Date &amp; Time"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/viewServiceType"
        android:id="@+id/textpickDateTime"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp" />
    <View
        android:layout_width="wrap_content"
        android:layout_height="44dp"
        android:layout_below="@id/view2"
        android:id="@+id/view3"
        android:background="#171717"
        android:layout_marginTop="5dp" />
    <TextView
        android:text="Select User"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/view2"
        android:id="@+id/textSelectUser"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp" />
</RelativeLayout>

footer.xml:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
  <View
        android:layout_width="wrap_content"
        android:layout_height="44dp"
        android:id="@+id/view4"
        android:background="#171717" />
    <TextView
        android:text="Add/Edit Remainder"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/listViewSaloonUser"
        android:id="@+id/textView1"
        android:layout_marginTop="12dp"
        android:layout_marginLeft="10dp" />
    <RelativeLayout
        android:id="@id/layoutlinear2"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="152.0dp"
        android:layout_below="@id/view4">
        <TextView
            android:layout_width="213.3dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="10dp"
            android:text="One day before appointment"
            android:id="@+id/servicetype1"
            android:gravity="center_vertical"
            android:textSize="15dp" />
        <ImageView
            android:src="@drawable/Unchecked"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/servicetype1"
            android:id="@+id/imageView2"
            android:layout_alignParentRight="true"
            android:layout_marginTop="-23dp"
            android:layout_marginRight="20dp" />
        <View
            android:layout_width="wrap_content"
            android:layout_height="0.2dp"
            android:layout_below="@id/servicetype1"
            android:id="@+id/seperator"
            android:visibility="visible"
            android:background="@drawable/hSeparator"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp" />
        <TextView
            android:layout_width="194.7dp"
            android:layout_below="@id/seperator"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Add custom Remainder"
            android:id="@+id/servicetype2"
            android:gravity="center_vertical"
            android:textSize="15dp" />
        <ImageView
            android:src="@drawable/Unchecked"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/servicetype1"
            android:id="@+id/imageviewunchecked"
            android:layout_alignParentRight="true"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp" />
        <View
            android:layout_width="wrap_content"
            android:layout_height="0.2dp"
            android:layout_below="@id/imageviewunchecked"
            android:id="@+id/seperator2"
            android:visibility="visible"
            android:background="@drawable/hSeparator"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp" />
        <TextView
            android:layout_width="194.7dp"
            android:layout_below="@id/seperator2"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Add Remainder to calender"
            android:id="@+id/servicetype2"
            android:gravity="center_vertical"
            android:textSize="15dp" />
        <ImageView
            android:src="@drawable/add"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_below="@id/servicetype2"
            android:id="@+id/imageView3"
            android:layout_alignParentRight="true"
            android:layout_marginRight="20dp"
            android:layout_marginTop="-23dp"
            android:layout_marginBottom="23dp" />
    </RelativeLayout>

主布局:

 <ListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_below="@id/view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listViewSaloonUser"
        android:layout_marginTop="140dp" />

现在在活动中获取listView参考和膨胀的标头和页脚,并做以下:

listView.addHeaderView(headerView,null,false);
listView.addFooterView(footerView);

相关内容

最新更新