【发布时间】:2016-07-17 12:43:27
【问题描述】:
我尝试让 水平滚动 像 google play 一样。像这样:
它滚动类似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);
适配器布局:
<?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>
适配器类:
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;
}
@Override
public NowShowingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.movie_for_list,null,false);
return new NowShowingViewHolder(view);
}
@Override
public void onBindViewHolder(NowShowingViewHolder holder, int position) {
holder.movieImage.setImageResource(movieImageId[position]);
}
public void setOnMovieClickListener(MovieListClick movieListClick){
this.movieListClick = movieListClick;
}
@Override
public int getItemCount() {
return movieImageId.length;
}
public class NowShowingViewHolder extends RecyclerView.ViewHolder {
public ImageView movieImage;
public NowShowingViewHolder(View itemView) {
super(itemView);
movieImage = (ImageView) itemView.findViewById(R.id.movieImage);
movieImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
movieListClick.onMovieClick(getLayoutPosition());
}
});
}
}
}
【问题讨论】:
-
在尝试这个链接之前我遇到了这样的问题Use RecyclerView inside ScrollView with flexible Recycler item height
-
什么意思?将最左边的项目对齐到边缘?
-
是的。我发现了一些需要检查手势的东西,但如果有任何内置函数会很有帮助。
标签: android android-viewpager android-recyclerview