/**
* Animate a scroll by the given amount of pixels along either axis.
*
* @param dx Pixels to scroll horizontally
* @param dy Pixels to scroll vertically
*/
public void smoothScrollBy(int dx, int dy) {
smoothScrollBy(dx, dy, null);
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorWhite"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="18dp"
android:gravity="center"
android:text="养车\n宝典"
android:textColor="@color/colorTitle"
android:textSize="12sp"/>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:layout_marginBottom="12dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="12dp"
android:background="@color/colorTitle"/>
<!--禁用了recyclerView的触摸事件,他的点击事件交由一个透明的蒙版来实现-->
<RelativeLayout
android:layout_marginLeft="6dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.xinshiwi.mycar.view.AutoScrollRecyclerView
android:id="@+id/rv_home_maintain"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/view_home_maintain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
</RelativeLayout>
</LinearLayout>
public class MaintainInfoAdapter extends RecyclerView.Adapter<MaintainInfoAdapter.MyViewHolder> {
List<String> list;
public MaintainInfoAdapter(List<String> list) {
this.list = list;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_maintain, null);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.tv.setText(list.get(position % 4));
}
@Override
public int getItemCount() {
return Integer.MAX_VALUE;
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
public TextView tv;
public MyViewHolder(View itemView) {
super(itemView);
tv = (TextView) itemView.findViewById(R.id.tv_maintain);
}
}
}
/**
* 滚动养车宝典
*/
private void initMaintainData() {
mList = new ArrayList<>();
mList.add("如何做好队汽车的轮胎养护0");
mList.add("如何做好队汽车的轮胎养护1");
mList.add("如何做好队汽车的轮胎养护2");
mList.add("如何做好队汽车的轮胎养护3");
mRvHomeMaintain.setLayoutManager(new LinearLayoutManager(mActivity));
mAdapter = new MaintainInfoAdapter(mList);
mRvHomeMaintain.setAdapter(mAdapter);
Message msg = new Message();
msg.what = MAINTAIN_INFO;
sHandler.sendMessageDelayed(msg, 3000);
//通过一个透明的蒙板来设置点击事件
mViewHomeMaintain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mActivity, "pos % 4:" + (pos % 4), Toast.LENGTH_SHORT).show();
}
});
}
//当前显示的item
private int pos = 0;
private Handler sHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case MAINTAIN_INFO:
mRvHomeMaintain.smoothScrollBy(0, SizeUtils.dp2px(60));
pos++;
Message message = new Message();
message.what = MAINTAIN_INFO;
sHandler.removeMessages(MAINTAIN_INFO);
sHandler.sendMessageDelayed(message, 3000);
break;
}
}
};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有