2017-10-10 133 views
-1

是否可以使用CoordinatorLayoutListView使用CoordinatorLayout和ListView

我試圖不工作

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingRight="15dp"> 

      <ru.boloid.giszkh.views.AppTextView 
       android:id="@+id/title_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dp" 
       android:layout_marginTop="10dp" 
       android:textColor="@android:color/white" 
       android:textSize="18sp"/> 

      <TextView 
       android:id="@+id/address_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dp" 
       android:textColor="@android:color/white" 
       android:textSize="15sp"/> 

     </LinearLayout> 

    </android.support.v7.widget.Toolbar> 

    <LinearLayout 
     android:id="@+id/no_payment_documents" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar" 
     android:background="#EBEFF0" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:visibility="gone"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:contentDescription="@null" 
      android:src="@drawable/attention"/> 

     <TextView 
      android:id="@+id/nothing_found_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/payment_documents_nothing_found_text_margin" 
      android:gravity="center" 
      android:text="@string/payment_documents_nothing_found"/> 

    </LinearLayout> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/toolbar"> 

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

      <android.support.v4.widget.NestedScrollView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" 
       android:fillViewport="true"> 
      <ListView 
       android:id="@+id/pay_list" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/footer" 
       android:background="@color/list_background" 
       android:divider="@null" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
      </android.support.v4.widget.NestedScrollView> 

      <!--<ListView--> 
       <!--android:id="@+id/pay_list"--> 
       <!--android:layout_width="match_parent"--> 
       <!--android:layout_height="wrap_content"--> 
       <!--android:layout_above="@+id/footer"--> 
       <!--android:background="@color/list_background"--> 
       <!--android:divider="@null"--> 
       <!--/>--> 

      <LinearLayout 
       android:id="@+id/footer" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:background="@color/list_background" 
       app:layout_scrollFlags="scroll|enterAlways" 
       android:orientation="vertical"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:padding="16dp"> 


        <LinearLayout 
         android:id="@+id/amount_to_pay_group" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center_vertical" 
         android:orientation="horizontal"> 

         <TextView 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:text="@string/payment_documents_total_accrued" 
          android:textColor="@color/pay_item_title_text_color" 
          android:textSize="@dimen/payment_documents_footer_text_size" 
          android:textStyle="bold"/> 

         <TextView 
          android:id="@+id/total_accrued" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:textColor="@color/pay_item_title_text_color" 
          android:textSize="@dimen/payment_documents_footer_text_size" 
          android:textStyle="bold" 
          tools:text="995 000.00 P"/> 

         <ImageView 
          android:id="@+id/info_amount_in_progress_image" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_margin="8dp" 
          android:contentDescription="@null" 
          android:scaleX="@dimen/controls_scale_1.4" 
          android:scaleY="@dimen/controls_scale_1.4" 
          android:src="@drawable/info_gray" 
          android:visibility="invisible"/> 

        </LinearLayout> 

        <LinearLayout 
         android:id="@+id/insurance_group" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center_vertical" 
         android:orientation="horizontal"> 

         <TextView 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:text="@string/payment_documents_insurance" 
          android:textColor="@color/pay_item_title_text_color" 
          android:textSize="@dimen/payment_documents_footer_text_size"/> 

         <TextView 
          android:id="@+id/insurance_amount" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:textColor="@color/pay_item_title_text_color" 
          android:textSize="@dimen/payment_documents_footer_text_size" 
          tools:text="132.84 P"/> 

         <ImageView 
          android:id="@+id/edit_insurance_image" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_margin="8dp" 
          android:contentDescription="@null" 
          android:scaleX="@dimen/controls_scale_1.4" 
          android:scaleY="@dimen/controls_scale_1.4" 
          android:src="@drawable/ic_edit"/> 

        </LinearLayout> 

        <LinearLayout 
         android:id="@+id/paid_amount_group" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center_vertical" 
         android:orientation="horizontal"> 

         <TextView 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:text="@string/payment_documents_paid" 
          android:textColor="@color/pay_item_title_text_color" 
          android:textSize="@dimen/payment_documents_footer_text_size"/> 

         <TextView 
          android:id="@+id/paid_amount" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginBottom="8dp" 
          android:layout_marginEnd="36dp" 
          android:layout_marginRight="36dp" 
          android:layout_marginTop="8dp" 
          android:textColor="@color/pay_item_title_text_color" 
          android:textSize="@dimen/payment_documents_footer_text_size" 
          tools:text="1 502 000.00 P"/> 

        </LinearLayout> 
       </LinearLayout> 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:background="@color/separator"/> 

       <ru.boloid.giszkh.views.AppButton 
        android:id="@+id/pay_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_margin="16dp" 
        android:drawableLeft="@drawable/ic_card" 
        android:drawablePadding="10dp" 
        android:minWidth="130dp"/> 
      </LinearLayout> 

     </RelativeLayout> 

    </android.support.design.widget.CoordinatorLayout> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="4dp" 
     android:layout_below="@id/toolbar" 
     android:background="@drawable/bkgrd_shadow"/> 
</RelativeLayout> 

另外一個問題如下: 如何使我的LinearLayout滾動到頂部,當我到達的ListView的底部?

+0

顯示你的整個XML佈局 –

+1

沒有,使用RecyclerView – EpicPandaForce

+0

燁運用recyclerview。檢查此https://github.com/chrisbanes/cheesesquare – Raghunandan

回答

1

你可以這樣做。

1.增加CustomListView

public class CustomListView extends ListView { 

    public CustomListView(Context context) { 
     super(context); 
    } 

    public CustomListView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public CustomListView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    public CustomListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2 
      , MeasureSpec.AT_MOST); 
     super.onMeasure(widthMeasureSpec, expandSpec); 
    } 
} 

2.change XML代碼

你改變這一點。

<ListView 
    android:id="@+id/lstTask" 
    android:layout_width="match_parent" 
    android:layout_height="287dp" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="12dp"/> 

<!-- your package name--> 
<com.your.app.utils.CustomListView 
    android:id="@+id/lstTask" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="12dp"/> 
+0

謝謝!我現在就試試 – ManOfWar

+0

謝謝!完美的作品。 – ManOfWar

+0

祝你好運!@ManOfWar – KeLiuyue

相關問題