我试图像谷歌一样进行水平滚动.就像这样:
它滚动的东西就像ViewPager
.只关注左侧的一个项目.但是当我实现RecyclerView
和Horizontal LineararLayout管理器,但滚动顺利但不像谷歌播放.代码已经给出了下面,任何人都可以帮助我使滚动完全像谷歌播放滚动?
Recyclerview宣言:
RecyclerView nowShowingMovies;
.......
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
nowShowingMovies.setLayoutManager(layoutManager);
nowShowingMovies.setHasFixedSize(true);
NowShowingAdapter adapter = new NowShowingAdapter(getActivity());
nowShowingMovies.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
适配器布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:clickable="true"
android:paddingRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/movieImage"
android:layout_width="144dp"
android:layout_height="200dp"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
AdapterClass:
public class NowShowingAdapter extends RecyclerView.Adapter<NowShowingAdapter.NowShowingViewHolder> {
MovieListClick movieListClick;
ArrayList<MovieListModel> movieListModel;
int movieImageId[] = new int[]{
R.drawable.kubo_image,
R.drawable.batman1,
R.drawable.jugnle_1,
R.drawable.kanfu_1,
R.drawable.peanuts,
R.drawable.sweetheart
};
Context context;
public NowShowingAdapter(Context context){
this.context = context;
} …
Run Code Online (Sandbox Code Playgroud) 我的Xml代码:
<Button
android:id="@+id/link_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/google_btn" />
Run Code Online (Sandbox Code Playgroud)
我正在应用默认涟漪效应
<Button
android:id="@+id/link_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" />
Run Code Online (Sandbox Code Playgroud)
但我需要按钮的背景"@drawable/google_btn"
用
"?android:attr/selectableItemBackground"
.这意味着我需要自定义背景的涟漪效果.