package wld.bawei.com.myonemoni.view; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Handler; import android.os.Message; import android.support.annotation.Nullable; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import java.util.ArrayList; import java.util.List; import wld.bawei.com.myonemoni.Bean; import wld.bawei.com.myonemoni.R; /** * Created by 大金鑫 on 2017/12/2. */ public class Mylunbo extends LinearLayout{ private LinearLayout ll; private ImageView imageView; private List<ImageView> image=new ArrayList<>(); Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); int currentItem = pager.getCurrentItem(); pager.setCurrentItem(currentItem+1); handler.sendEmptyMessageDelayed(0,5000); } }; private ViewPager pager; private View view; public Mylunbo(Context context) { this(context,null); } public Mylunbo(Context context, @Nullable AttributeSet attrs) { this(context, attrs,0); } public Mylunbo(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { view = View.inflate(getContext(), R.layout.lunbo, this); pager = view.findViewById(R.id.pager); jiadian(); handler.sendEmptyMessage(5000); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { for (int i=0;i<image.size();i++) { if(i==position%image.size()) { image.get(i).setImageResource(R.drawable.dot_focuable);//修改图片颜色 }else { image.get(i).setImageResource(R.drawable.dot_normal); } } } @Override public void onPageScrollStateChanged(int state) { } }); } public void jiadian() { Log.e("aaa","aaa"); //得到LinearLayout布局 ll = (LinearLayout) view.findViewById(R.id.ll); image.clear();//清空图片集合 ll.removeAllViews();//清空LinearLayout布局 for (int i=0;i<4;i++)//添加 { //创建一个图片布局 imageView = new ImageView(getContext()); if(i==0) { imageView.setImageResource(R.drawable.dot_focuable); }else { imageView.setImageResource(R.drawable.dot_normal); } LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(20, 20);//圆点大小 image.add(imageView);//圆点添加到图片集合中 ll.addView(imageView,layoutParams);//圆点添加到LinearLayout中 } } public void setAdapter(Myadapter myadapter){ pager.setAdapter(myadapter); } }
Imageview
最新推荐文章于 2019-08-22 11:14:00 发布