Android为TV端助力 最简单的自定义圆点view

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

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/point_bg_enable" android:state_enabled="true"></item>
<item android:drawable="@drawable/point_bg_normal" android:state_enabled="false"></item>
</selector>

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

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<corners android:radius="5dp"/>
<solid android:color="#FFFF0000" />
</shape>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<corners android:radius="5dp" />
<solid android:color="#FF000000" />
</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作为背景,然后设置第一个问启动状态,这样我们的自定义圆点就完成的

 

posted @ 2016-04-21 14:39  水柠檬QAQ  阅读(4059)  评论(0编辑  收藏  举报