效果演示
一、对布局的设置
1. 在activity_main.xml 文件中使用RelativeLayout 布局 创建一个Viewpager
2.创建一个RadioGroup,并创建三个单选按钮(RadioButton)
分别命名为 dot_ 1, dot_2 , dot_3 将RadioGroup命名为: rg_dot
布局界面源代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.viewpager.widget.ViewPager
android:id="@+id/lunbo"
android:layout_width="match_parent"
android:layout_margin="20dp"
android:layout_height="250dp"/>
<RadioGroup
android:id="@+id/rg_dot"
android:orientation="horizontal"
android:layout_width="match_parent"
android:gravity="center"
android:layout_marginTop="200dp"
android:layout_height="30dp">
<RadioButton
android:id="@+id/dot_1"
android:layout_marginRight="15dp"
android:layout_width="20dp"
android:button="@null"
android:layout_height="20dp"/>
<RadioButton
android:id="@+id/dot_2"
android:layout_marginRight="15dp"
android:layout_width="20dp"
android:button="@null"
android:layout_height="20dp"/>
<RadioButton
android:id="@+id/dot_3"
android:layout_marginRight="15dp"
android:layout_width="20dp"
android:button="@null"
android:layout_height="20dp"/>
</RadioGroup>
</RelativeLayout>
对圆点样式的创建
1.在res\drawable下创建文件
2. 创建两个文件 分别是 :dot_select(选中时) 和 dot_noselect(未选中时)
3. 修改样式
4.导入轮播图所需要的图片
三.对MainActivity.class的编写
1. 声明变量并获取控件