我在片段中有回收视图。当在循环器视图中单击项目时,我调用方法替换片段。 我将ripple.xml自定义为后台项目recyclerview,但在替换时不显示动画。 这是我的代码: custom_bg.xml for api< 20
<?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>
&#13;
<?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>
&#13;
<?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>
&#13;
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());
}
});
}
}
&#13;
并在myfragment.class中调用
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);
}
}
}
}
}
});
&#13;
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();
}
&#13;
答案 0 :(得分:0)
请使用此
android:foreground="?attr/selectableItemBackground"
或者
android:foreground="?android:attr/selectableItemBackground"
或者
android:background="?attr/selectableItemBackground"
或者
android:background="?android:attr/selectableItemBackground"
在recyclerview的item.xml的父布局中,这将自动生成涟漪效应。