2017-05-24 2 views
0

J'ai une vue recycleur dans un fragment. Lorsque vous cliquez sur l'élément dans la vue Recycleur, j'appelle la méthode Remplacer le fragment. J'ai customisé un fichier ripple.xml à recyclerview, mais il ne montre pas d'animation quand replace. Voici mon code: custom_bg.xml pour api L'effet d'ondulation ne fonctionne pas lors de l'appel d'une vue recycleur d'objets avec evetn remplacer le fragment

<?xml version="1.0" encoding="utf-8"?> 
 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
 
    <item android:state_pressed="true"> 
 
     <shape> 
 
      <solid android:color="@android:color/holo_blue_light"></solid> 
 
     </shape> 
 
    </item> 
 
    <item > 
 
     <shape> 
 
      <solid android:color="@android:color/white"></solid> 
 
     </shape> 
 
    </item> 
 
</selector>
effet d'entraînement de custom_bg.xml

<?xml version="1.0" encoding="utf-8"?> 
 
<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:color="?android:attr/colorControlHighlight"> 
 
    <item 
 
     android:id="@android:id/mask" 
 
     android:drawable="@android:color/white"> 
 
    </item> 
 
</ripple>
item.xml

<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:id="@+id/mRoot" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="@dimen/game_ll_item_list" 
 
    android:background="@drawable/custom_bg"> 
 

 
    <LinearLayout 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignParentLeft="true" 
 
     android:layout_centerVertical="true" 
 
     android:layout_toLeftOf="@+id/mTvScore" 
 
     android:gravity="center" 
 
     android:orientation="vertical"> 
 

 
     <TextView 
 
      android:id="@+id/mTvNameTeamA" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center" 
 
      android:ellipsize="marquee" 
 
      android:focusable="true" 
 
      android:focusableInTouchMode="true" 
 
      android:marqueeRepeatLimit="marquee_forever" 
 
      android:singleLine="true" 
 
      android:textSize="@dimen/game_tv_item_team_size" 
 
      tools:text="朝日南" /> 
 

 
     <TextView 
 
      android:id="@+id/mTvNameTeamASmall" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center" 
 
      android:singleLine="true" 
 
      android:textSize="@dimen/text_size_20pt" 
 
      tools:text="(東東京)" /> 
 
    </LinearLayout> 
 

 
    <TextView 
 
     android:id="@+id/mTvScore" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_centerInParent="true" 
 
     android:layout_marginLeft="@dimen/game_tv_item_score_margin_left_right" 
 
     android:layout_marginRight="@dimen/game_tv_item_score_margin_left_right" 
 
     android:gravity="center" 
 
     android:textColor="@android:color/black" 
 
     android:textSize="@dimen/game_tv_item_score_size" 
 
     android:textStyle="bold" 
 
     tools:text="2-8" /> 
 

 
    <LinearLayout 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_centerVertical="true" 
 
     android:layout_toLeftOf="@+id/mImgArrow" 
 
     android:layout_toRightOf="@+id/mTvScore" 
 
     android:gravity="center" 
 
     android:orientation="vertical"> 
 

 
     <TextView 
 
      android:id="@+id/mTvNameTeamB" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center" 
 
      android:ellipsize="marquee" 
 
      android:focusable="true" 
 
      android:focusableInTouchMode="true" 
 
      android:marqueeRepeatLimit="marquee_forever" 
 
      android:singleLine="true" 
 
      android:textSize="@dimen/game_tv_item_team_size" 
 
      tools:text="ABC工科" /> 
 

 
     <TextView 
 
      android:id="@+id/mTvNameTeamBSmall" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center" 
 
      android:singleLine="true" 
 
      android:textSize="@dimen/text_size_20pt" 
 
      tools:text="(東東京)" /> 
 
    </LinearLayout> 
 

 
    <ImageView 
 
     android:id="@+id/mImgArrow" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignParentEnd="true" 
 
     android:layout_alignParentRight="true" 
 
     android:layout_centerVertical="true" 
 
     android:contentDescription="@null" 
 
     android:padding="@dimen/game_img_list_padding" 
 
     android:src="@drawable/ic_arrow_right_pink" 
 
     android:visibility="invisible" /> 
 

 
    <View 
 
     android:id="@+id/mViewLine" 
 
     style="@style/CommonLine" 
 
     android:layout_alignParentBottom="true" /> 
 
</RelativeLayout>
et myadapter.class i événement appelle

private class ContentViewHolder extends RecyclerView.ViewHolder { 
 
     
 
     private final RelativeLayout mRoot; 
 

 
     public ContentViewHolder(View itemView) { 
 
      super(itemView); 
 
      mRoot = (RelativeLayout) itemView.findViewById(R.id.mRoot); 
 
      mRoot.setOnClickListener(new View.OnClickListener() { 
 
       @Override 
 
       public void onClick(View v) { 
 
        mListener.onItemClick(getLayoutPosition()); 
 
       } 
 
      }); 
 
     } 
 
    }

et myfragment.class j'appelle

mAdapter = new GameListAdapter(mContext, new GameListAdapter.OnGameAdapterListener() { 
 
      @Override 
 
      public void onItemClick(int position) { 
 
       if (position < mObjects.size()) { 
 
        Object object = mObjects.get(position); 
 
        if (object instanceof Schedule) { 
 
         if (getParentFragment() instanceof BaseContainerFragment) { 
 
          if (!isItemClicked) { 
 
           isItemClicked = true; 
 
           ((BaseContainerFragment) getParentFragment()).replaceFragment(GameDetailFragment_.builder().mSchedule((Schedule) object).build(), true); 
 
          } 
 
         } 
 
        } 
 
       } 
 
      } 
 
     });

public void replaceFragment(Fragment fragment, boolean addToBackStack) { 
 
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 
 
transaction.setCustomAnimations(R.anim.slide_in_right, 0); 
 
     if (addToBackStack) { 
 
      transaction.addToBackStack(null); 
 
     } 
 
     transaction.replace(R.id.mFrameContainer, fragment); 
 
     transaction.commitAllowingStateLoss(); 
 
    }
J'ai essayé de post-retarder l'animation du spectacle mais c'est très décalé. Comment je peux le réparer? Merci beaucoup!

Répondre

0

S'il vous plaît utiliser ce

android:foreground="?attr/selectableItemBackground" 

ou cette

android:foreground="?android:attr/selectableItemBackground" 

ou cette

android:background="?attr/selectableItemBackground" 

ou cette

android:background="?android:attr/selectableItemBackground" 

dans la disposition parent de item.xml de recyclerview cela générera automatiquement un effet d'entraînement.