zoukankan      html  css  js  c++  java
  • 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作为背景,然后设置第一个问启动状态,这样我们的自定义圆点就完成的

  • 相关阅读:
    codeforces 985 F. Isomorphic Strings
    Educational Codeforces Round 44
    codeforces 979D
    ARC060 Digit Sum II
    Iroha and Haiku II
    Unhappy Hacking II
    Just h-index 2018湘潭邀请赛
    [HAOI2007]理想的正方形
    P1231 教辅的组成
    最小割数学形式
  • 原文地址:https://www.cnblogs.com/xiaoxiaing/p/5416856.html
Copyright © 2011-2022 走看看