Android ViewPager中动态生成底部圆点
2016-06-24 11:23
465 查看
private void initCircleViews() { LinearLayout ll_circle = (LinearLayout) findViewById(R.id.ll_circles); circles = new ArrayList<>(); // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.shape_circle_gray); for (int i = 0; i < adapter.getPageCount(sl.getPerPageNum()); i++) { View view = new View(this); // view.setLayoutParams(new ViewGroup.LayoutParams(bitmap.getWidth(),bitmap.getHeight())); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(20, 20); layoutParams.setMargins(10,0,0,0); view.setLayoutParams(layoutParams); view.setBackgroundResource(R.drawable.shape_circle_gray); ll_circle.addView(view); circles.add(view); } } void setCircleView(int currentPage){ for (View view:circles){ view.setBackgroundResource(R.drawable.shape_circle_gray); } circles.get(currentPage).setBackgroundResource(R.drawable.shape_circle_red); } shape_circle_red.xml shape_circle_gray.xml <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <!-- 填充颜色 --> <solid android:color="@android:color/darker_gray" ></solid> <!--线的宽度,颜色灰色--> <stroke android:width="2dp" android:color="@android:color/darker_gray"></stroke> <!-- 矩形的圆角半径 --> <corners android:radius="5dp" /> </shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <!-- 填充颜色 --> <solid android:color="@android:color/holo_red_light" ></solid> <!--线的宽度,颜色灰色--> <stroke android:width="2dp" android:color="@android:color/holo_red_light"></stroke> <!-- 矩形的圆角半径 --> <corners android:radius="5dp" /> </shape>
相关文章推荐
- 解决Android 5.0以上Button自带阴影的问题
- Android开发中Handler的案例分析
- 浅谈 PopupWindow 在 Android 开发中的使用
- android 获取手机的运营商
- Android中R文件的丢失问题
- android笔记之关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- Android Theme 的一些简单信息
- Android通过JmDNS查找和注册设备的方法
- android竖排显示TextView
- Android NDK开发
- Android 倒计时 小Demo
- android常用的侧滑面板
- Android service(二)绑定服务
- 设置Scr a8fa ollView的滚动条为隐藏的方法,scrollview滚动条
- gvr-android-sdk 初探
- Android 获取屏幕的分辨率
- Rxandroid+Retrofit学习记录
- Android 数据库 GreenDao使用
- Android如何选择targetSDKVersion
- Xamarin Android项目提示SDK版本太老