繁体   English   中英

禁用从ListView向下滚动-Android

[英]Disable scroll down from ListView - Android

我有一个Activity,在其末尾具有多个TextViews和一个ListView。 我注意到ListView有其自己的向下滚动,我想做的就是禁用ListView向下滚动并为整个屏幕创建一个ScrollView。 我可以这样做吗?

这是Activity的XML:

编辑:我为屏幕添加了一个scrollView,但是它以某种方式影响了ListView,因为它仅显示列表的一项。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbarOrderDetail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@drawable/topbg"
        android:minHeight="?attr/actionBarSize">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/lblBackButtonOrderDetail"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:onClick="goBackToTabs"
                android:layout_marginTop="@dimen/margin_five"
                android:drawableLeft="@drawable/back" />

            <TextView
                android:id="@+id/lblOrderDetailHeader"
                fontPath="fonts/Roboto-Bold.ttf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:text="Order Details"
                android:textSize="21sp" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|left"
            android:orientation="vertical"
            android:paddingLeft="8dp"
            android:paddingRight="8dp">

    <TextView
        android:id="@+id/lblOrderId"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbarOrderDetail"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="@string/order_id"
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblOrderIdData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblOrderId"
        android:layout_alignTop="@+id/lblOrderId"
        android:layout_below="@+id/toolbarOrderDetail"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_toRightOf="@+id/lblOrderId"
        android:gravity="center"
        android:text="" />

    <View
        android:id="@+id/viewOrder1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lblOrderId"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@color/line_color"></View>

    <TextView
        android:id="@+id/lblBeestroNameHeader"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/viewOrder1"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="@string/bistro_name"
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblBistroName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblBeestroNameHeader"
        android:layout_alignTop="@+id/lblBeestroNameHeader"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_toRightOf="@+id/lblBeestroNameHeader"
        android:gravity="center"
        android:text="" />

    <View
        android:id="@+id/viewOrder2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lblBeestroNameHeader"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@color/line_color"></View>

    <TextView
        android:id="@+id/lblOrderStatus"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/viewOrder2"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="@string/order_status"
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblOrder"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblOrderStatus"
        android:layout_alignTop="@+id/lblOrderStatus"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_toRightOf="@+id/lblOrderStatus"
        android:gravity="center"
        android:text=""
        android:textColor="@android:color/holo_red_light" />

    <View
        android:id="@+id/viewOrder3"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lblOrderStatus"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@color/line_color"></View>

    <TextView
        android:id="@+id/lblPaymentMethodHeader"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/viewOrder3"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="@string/payment_method"
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblPaymentMethod"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblPaymentMethodHeader"
        android:layout_alignTop="@+id/lblPaymentMethodHeader"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_toRightOf="@+id/lblPaymentMethodHeader"
        android:gravity="center"
        android:text="" />

    <View
        android:id="@+id/viewOrder4"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lblPaymentMethod"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@color/line_color"></View>

    <TextView
        android:id="@+id/lblDate"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/viewOrder4"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="Date: "
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblDateTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblDate"
        android:layout_alignTop="@+id/lblDate"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_toRightOf="@+id/lblDate"
        android:gravity="center"
        android:text="" />

    <View
        android:id="@+id/viewOrder5"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lblDate"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@color/line_color"></View>

    <TextView
        android:id="@+id/lblTime"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/viewOrder5"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="Time: "
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblTimeTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblTime"
        android:layout_alignTop="@+id/lblTime"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_toRightOf="@+id/lblTime"
        android:gravity="center"
        android:text="" />

    <View
        android:id="@+id/viewOrder6"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lblTime"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@color/line_color"></View>

    <TextView
        android:id="@+id/lblTotal"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/viewOrder6"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="Total Price: "
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblTotalTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblTotal"
        android:layout_alignTop="@+id/lblTotal"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_toRightOf="@+id/lblTotal"
        android:gravity="center"
        android:text="" />

    <View
        android:id="@+id/viewOrder7"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lblTotal"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@color/line_color"></View>

    <TextView
        android:id="@+id/lblItem"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/viewOrder7"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="Items Ordered:"
        android:textSize="@dimen/activity_horizontal_margin" />

    <TextView
        android:id="@+id/lblItem1"
        fontPath="fonts/Roboto-Bold.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lblItem"
        android:layout_marginLeft="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:text="Name/Quantity/Price"
        android:textSize="@dimen/activity_horizontal_margin" />

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/lblItem1"
        android:layout_marginBottom="@dimen/margin_ten"
        android:layout_marginTop="@dimen/margin_ten"
        android:background="@android:color/transparent"
        android:divider="@color/line_color"
        android:dividerHeight="1dp"
        android:scrollbars="none" />

    <include
        android:id="@+id/beeGif"
        layout="@layout/view_bee_animation"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"></include>

        </LinearLayout>

    </ScrollView>


</LinearLayout>

这应该工作。

listView.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM