首先创建一个选择器,用来判断圆点状态,可以根本自己的需求改

<selector xmlns:andro></item>
</selector>

然后在定义圆点的大小和颜色

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:andro />
</shape>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:andro />
</shape>

我这里创建的两个shape文件,主要区别于当圆点启动时是红色,不启动时是黑色,可以根据自己的需求改,接下来就是代码上面的引用

LinearLayout dotlayout=(LinearLayout)findViewById(R.id.dotViewLayout);
for(int i=1;i<=3;i++){
View dot=new View(this);
dot.setBackgroundResource(
R.drawable.point_background);
LayoutParams params=
new LayoutParams(10,10);
params.leftMargin=20;
dot.setLayoutParams(params);
dot.setEnabled(false);
dotlayout.addView(dot);
}
dotlayout.getChildAt(0).setEnabled(true);

我这里创建的三个圆点,并设置我们刚刚新建的selector作为背景,然后设置第一个问启动状态,这样我们的自定义圆点就完成的

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
相关资源
相似解决方案