2016-07-15 39 views
1

我試圖給MvxListView添加漣漪效應,但它沒有來。這是佈局。給列表視圖添加漣漪效應

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/orientedlayout" 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:baselineAligned="false"> 
    <LinearLayout 
     android:layout_weight="0.4" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:id="@+id/linearLayout2" 
     android:orientation="vertical" 
     android:layout_marginLeft="5dp" 
     android:layout_marginTop="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginBottom="5dp"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.3" 
      android:id="@+id/linearLayout2"> 
      <cgs.bw.droid.CustomCalendar 
       android:id="@+id/customcalender" 
       android:orientation="vertical" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="0.7" /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.7" 
      android:weightSum="2" 
      android:id="@+id/linearLayout2" 
      android:orientation="vertical" 
      android:layout_marginTop="5dp"> 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="56dp" 
       android:gravity="center_vertical" 
       android:textAlignment="center"> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 
        <TextView 
         android:gravity="center" 
         android:id="@+id/txtActivity" 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:text="@string/strActivity" 
         android:textSize="@dimen/textsize_medium" 
         android:tag="RobotoCondensedBold" 
         android:layout_weight="1" 
         android:textColor="#9b9b9b" 
         android:textColorLink="#7e1664" 
         android:layout_marginLeft="10dp" /> 
        <View 
         android:layout_width="match_parent" 
         android:layout_height="1dp" 
         android:id="@+id/viewActivity" 
         android:background="#7e1664" 
         android:layout_marginLeft="10dp" /> 
       </LinearLayout> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="20dp"> 
        <TextView 
         android:id="@+id/txtNews" 
         android:gravity="center" 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:text="@string/strNews" 
         android:textSize="@dimen/textsize_medium" 
         android:tag="RobotoCondensedBold" 
         android:layout_weight="1" 
         android:textColor="#9b9b9b" 
         android:textColorLink="#7e1664" 
         android:paddingLeft="10dp" /> 
        <View 
         android:layout_width="match_parent" 
         android:layout_height="1dp" 
         android:id="@+id/viewNews" 
         android:background="#7e1664" 
         android:layout_marginLeft="10dp" /> 
       </LinearLayout> 
      </LinearLayout> 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
       <View 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:background="#e3e3e3" /> 
      </LinearLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:orientation="horizontal" 
       android:layout_height="0dp" 
       android:layout_weight="1.6" 
       android:id="@+id/ActivityLinLayout" 
       android:minHeight="80dp"> 
       <TextView 
        android:text="@string/NoActivityFeed" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        local:MvxBind="Visible (ActivityfeedData.Count==0)" 
        android:gravity="center" 
        android:textSize="@dimen/textsize_login" /> 
       <FrameLayout 
        android:minWidth="25px" 
        android:minHeight="25px" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
        <Mvx.MvxListView 
         local:MvxBind="ItemsSource ActivityfeedData ; ItemClick ShowDetails,Mode=TwoWay" 
         local:MvxItemTemplate="@layout/homeactivity_itemtemplate" 
         android:minWidth="25px" 
         android:minHeight="25px" 
     android:listSelector="@drawable/list_selector" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:drawSelectorOnTop="true"/> 
       </FrameLayout> 
      </LinearLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:orientation="horizontal" 
       android:layout_height="wrap_content" 
       android:id="@+id/NewsLinLayout" 
       android:layout_weight="1.6" 
       android:minHeight="80dp"> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:layout_gravity="right"> 
        <ImageView 
         android:src="@drawable/gear_icon_states" 
         android:layout_width="20dp" 
         android:layout_height="20dp" 
         android:id="@+id/imageView1" 
         local:MvxBind="Click EditFeedList" 
         android:layout_gravity="right" 
         android:padding="5dp" 
         android:layout_alignParentRight="true" /> 
        <TextView 
         android:text="@string/NoNews" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         local:MvxBind="Visible (FeedItemsTotal.Count==0)" 
         android:gravity="center" 
         android:textSize="@dimen/textsize_login" /> 
        <FrameLayout xmlns:tools="http://schemas.android.com/tools" 
         android:minWidth="25px" 
         android:minHeight="25px" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:visibility="visible" 
         tools:visibility="visible"> 
         <Mvx.MvxListView 
          local:MvxBind="ItemsSource FeedItemsTotal; ItemClick ShowNewsDetail,Mode=TwoWay" 
          local:MvxItemTemplate="@layout/homenewsfeedtemplate" 
          android:minWidth="25px" 
          android:minHeight="25px" 
     android:listSelector="@drawable/list_selector" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
         android:drawSelectorOnTop="true" /> 
        </FrameLayout> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_weight="0.6" 
     android:layout_width="0dp" 
     android:orientation="vertical" 
     android:layout_height="match_parent" 
     android:id="@+id/linearLayout1" 
     android:layout_marginTop="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginBottom="5dp"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.2"> 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.8" 
       android:textAlignment="center" 
       android:gravity="left" 
       android:layout_gravity="center" 
       android:layout_marginLeft="10dp"> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="20dp"> 
        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"> 
         <TextView 
          android:gravity="center" 
          android:id="@+id/txtAllEventsAndMeetings" 
          android:layout_width="wrap_content" 
          android:layout_height="match_parent" 
          android:text="@string/strAll" 
          android:layout_weight="1" 
          local:MvxBind="Click GoFetchAllMeetingAndEvents" 
          android:textSize="@dimen/textsize_medium" 
          android:tag="RobotoCondensedBold" 
          android:textColor="#9b9b9b" 
          android:textColorLink="#7e1664" /> 
         <View 
          android:layout_width="match_parent" 
          android:layout_height="1dp" 
          android:id="@+id/viewAllEventsAndMeetings" 
          android:background="#7e1664" /> 
        </LinearLayout> 
       </LinearLayout> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="20dp"> 
        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"> 
         <TextView 
          android:gravity="center" 
          android:id="@+id/txtEvents" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/strEvents" 
          android:layout_weight="1" 
          local:MvxBind="Click GoFetchAllEvents" 
          android:textSize="@dimen/textsize_medium" 
          android:tag="RobotoCondensedBold" 
          android:textColor="#9b9b9b" 
          android:textColorLink="#7e1664" /> 
         <View 
          android:layout_width="match_parent" 
          android:layout_height="1dp" 
          android:id="@+id/viewEvents" 
          android:background="#7e1664" /> 
        </LinearLayout> 
       </LinearLayout> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="20dp"> 
        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"> 
         <TextView 
          android:gravity="center" 
          android:id="@+id/txtMeetings" 
          android:layout_width="wrap_content" 
          android:layout_height="match_parent" 
          android:text="@string/strMeetings" 
          android:layout_weight="1" 
          local:MvxBind="Click GoFetchAllMeetings" 
          android:layout_marginRight="1dp" 
          android:textSize="@dimen/textsize_medium" 
          android:tag="RobotoCondensedBold" 
          android:textColor="#9b9b9b" 
          android:textColorLink="#7e1664" /> 
         <View 
          android:layout_width="match_parent" 
          android:layout_height="1dp" 
          android:id="@+id/viewMeetings" 
          android:background="#7e1664" /> 
        </LinearLayout> 
       </LinearLayout> 
      </LinearLayout> 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.2" 
       android:id="@+id/txtDate" 
       android:layout_gravity="center" 
       android:gravity="right"> 
       <TextView 
        android:gravity="center" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:text="@string/strToday" 
        android:layout_marginRight="1dp" 
        android:textSize="@dimen/textsize_medium" 
        android:tag="RobotoCondensedBold" 
        android:textColor="#4a90e2" 
        android:textColorLink="#7e1664" /> 
      </LinearLayout> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:layout_height="0dp" 
      android:id="@+id/frameLayout1" 
      android:layout_weight="1.8" 
      android:minHeight="80dp"> 
      <TextView xmlns:tools="http://schemas.android.com/tools" 
       android:text="@string/NoMeetingsforthisMonth" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/tv_no_evnt" 
       android:gravity="center" 
       android:visibility="gone" 
       tools:visibility="gone" /> 
      <Mvx.MvxListView xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/mvl" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:smoothScrollbar="true" 
       android:scrollingCache="false" 
       android:animationCache="false" 
       local:MvxBind="ItemsSource _MeetingList; ItemClick ShowMeetingDetail,Mode=TwoWay" 
       android:layout_marginLeft="@dimen/border_5dp" 
       android:layout_marginRight="@dimen/border_5dp" 
       tools:visibility="gone" 
     android:listSelector="@drawable/list_selector" 
         android:drawSelectorOnTop="true" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

我試圖機器人:listSelector = 「@繪製/ list_selector」 和機器人:drawSelectorOnTop = 「真」,但效果未顯示向上。有沒有別的應用程序的列表視圖。

這裏是list_selector:

<?xml version="1.0" encoding="utf-8"?> 
<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    android:color="@color/lg_pressed_state"> 
    <item android:drawable="@color/purple_bw"/> 
</ripple> 

在此先感謝。

回答

1

我開始實現這個包裹LinearLayout內部的項目佈局,並添加了紋波。

請嘗試,讓我知道:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/ripple_effect" 
    android:orientation="vertical"> 

    <RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/rltContent" 
     android:background="@color/youBackground" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!-- Your content here --> 

    </RelativeLayout> 
</LinearLayout> 

紋波例如:

<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorPrimaryDark"> 
    <item android:drawable="@color/colorPrimary" /> 
</ripple> 
+0

不..它不起作用。這是我的佈局的複雜性嗎? – Akshat

+0

你是否在pos API 21中測試它?請使用更簡單的佈局嘗試我的解決方案。只是爲了確保它的工作。然後繼續緩慢添加您的佈局。 – jzeferino

+0

好的..會嘗試讓你知道..感謝您的解決方案.. :) :) – Akshat

0

設置時android:background="?selectableItemBackground"到列表中的項目並添加的onClick監聽器(不聽者,還有我一直有成功點擊該項目時沒有漣漪)。

也許它也可以將此背景設置爲整個列表或樣式;否則,您必須爲列表項目創建單獨的佈局文件。