java与ListView一起使用CoordinatorLayout
可以将CoordinatorLayout
与ListView
一起使用吗
我试过以下方法,但不起作用
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<安卓.support.v7.widget.Toolbar
安卓:id="@+id/toolbar"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:background="?attr/colorPrimary"
安卓:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="vertical"
安卓:paddingRight="15dp">
<ru.boloid.giszkh.views.AppTextView
安卓:id="@+id/title_text"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_marginBottom="10dp"
安卓:layout_marginTop="10dp"
安卓:textColor="@安卓:color/white"
安卓:textSize="18sp"/>
<TextView
安卓:id="@+id/address_text"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_marginBottom="10dp"
安卓:textColor="@安卓:color/white"
安卓:textSize="15sp"/>
</LinearLayout>
</安卓.support.v7.widget.Toolbar>
<LinearLayout
安卓:id="@+id/no_payment_documents"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_below="@+id/toolbar"
安卓:background="#EBEFF0"
安卓:gravity="center"
安卓:orientation="vertical"
安卓:visibility="gone">
<ImageView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:contentDescription="@null"
安卓:src="@drawable/attention"/>
<TextView
安卓:id="@+id/nothing_found_text"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginTop="@dimen/payment_documents_nothing_found_text_margin"
安卓:gravity="center"
安卓:text="@string/payment_documents_nothing_found"/>
</LinearLayout>
<安卓.support.design.widget.CoordinatorLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_below="@+id/toolbar">
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<安卓.support.v4.widget.NestedScrollView
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
安卓:fillViewport="true">
<ListView
安卓:id="@+id/pay_list"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_above="@+id/footer"
安卓:background="@color/list_background"
安卓:divider="@null"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</安卓.support.v4.widget.NestedScrollView>
<!--<ListView-->
<!--安卓:id="@+id/pay_list"-->
<!--安卓:layout_width="match_parent"-->
<!--安卓:layout_height="wrap_content"-->
<!--安卓:layout_above="@+id/footer"-->
<!--安卓:background="@color/list_background"-->
<!--安卓:divider="@null"-->
<!--/>-->
<LinearLayout
安卓:id="@+id/footer"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_alignParentBottom="true"
安卓:background="@color/list_background"
app:layout_scrollFlags="scroll|enterAlways"
安卓:orientation="vertical">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="vertical"
安卓:padding="16dp">
<LinearLayout
安卓:id="@+id/amount_to_pay_group"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:gravity="center_vertical"
安卓:orientation="horizontal">
<TextView
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:text="@string/payment_documents_total_accrued"
安卓:textColor="@color/pay_item_title_text_color"
安卓:textSize="@dimen/payment_documents_footer_text_size"
安卓:textStyle="bold"/>
<TextView
安卓:id="@+id/total_accrued"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textColor="@color/pay_item_title_text_color"
安卓:textSize="@dimen/payment_documents_footer_text_size"
安卓:textStyle="bold"
tools:text="995 000.00 P"/>
<ImageView
安卓:id="@+id/info_amount_in_progress_image"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_margin="8dp"
安卓:contentDescription="@null"
安卓:scaleX="@dimen/controls_scale_1.4"
安卓:scaleY="@dimen/controls_scale_1.4"
安卓:src="@drawable/info_gray"
安卓:visibility="invisible"/>
</LinearLayout>
<LinearLayout
安卓:id="@+id/insurance_group"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:gravity="center_vertical"
安卓:orientation="horizontal">
<TextView
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:text="@string/payment_documents_insurance"
安卓:textColor="@color/pay_item_title_text_color"
安卓:textSize="@dimen/payment_documents_footer_text_size"/>
<TextView
安卓:id="@+id/insurance_amount"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textColor="@color/pay_item_title_text_color"
安卓:textSize="@dimen/payment_documents_footer_text_size"
tools:text="132.84 P"/>
<ImageView
安卓:id="@+id/edit_insurance_image"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_margin="8dp"
安卓:contentDescription="@null"
安卓:scaleX="@dimen/controls_scale_1.4"
安卓:scaleY="@dimen/controls_scale_1.4"
安卓:src="@drawable/ic_edit"/>
</LinearLayout>
<LinearLayout
安卓:id="@+id/paid_amount_group"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:gravity="center_vertical"
安卓:orientation="horizontal">
<TextView
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:text="@string/payment_documents_paid"
安卓:textColor="@color/pay_item_title_text_color"
安卓:textSize="@dimen/payment_documents_footer_text_size"/>
<TextView
安卓:id="@+id/paid_amount"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginBottom="8dp"
安卓:layout_marginEnd="36dp"
安卓:layout_marginRight="36dp"
安卓:layout_marginTop="8dp"
安卓:textColor="@color/pay_item_title_text_color"
安卓:textSize="@dimen/payment_documents_footer_text_size"
tools:text="1 502 000.00 P"/>
</LinearLayout>
</LinearLayout>
<View
安卓:layout_width="match_parent"
安卓:layout_height="1dp"
安卓:background="@color/separator"/>
<ru.boloid.giszkh.views.AppButton
安卓:id="@+id/pay_text"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_gravity="center"
安卓:layout_margin="16dp"
安卓:drawableLeft="@drawable/ic_card"
安卓:drawablePadding="10dp"
安卓:minWidth="130dp"/>
</LinearLayout>
</RelativeLayout>
</安卓.support.design.widget.CoordinatorLayout>
<View
安卓:layout_width="match_parent"
安卓:layout_height="4dp"
安卓:layout_below="@id/toolbar"
安卓:background="@drawable/bkgrd_shadow"/>
</RelativeLayout>
还有一个问题: 当我到达列表视图的底部时,如何使我的LinearLayout滚动到顶部
# 1 楼答案
你可以这样做
一,。添加
CustomListView
二,。更改xml代码
你可以改变这个
到
# 2 楼答案
您不应该需要自定义ListView子类。只要包含以下属性,ListView将直接与CoordinatorLayout配合使用:
然后,可以使用嵌套启用的ListView,使用方式与使用NestedScrollView或RecyclerView完全相同