一、效果图:
二、布局文件
header_view.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app1="http://schemas.android.com/apk/res/com.johnny.flowindicatortest" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Gallery android:id="@+id/home_gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" android:spacing="5dp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="#65000000" android:orientation="vertical" > <TextView android:id="@+id/tv_gal_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:textColor="#ffffff" android:textSize="18sp" /> <com.johnny.flowindicatortest.FlowIndicator android:id="@+id/myview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:gravity="center" app:count="4" app:point_normal_color="#45000000" app:point_radius="3dip" app:point_seleted_color="#ffffff" app:point_size="5dip" app:space="10dp" /> </LinearLayout> </FrameLayout>
gallery_item.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/home_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" android:src="@drawable/t1" /> </FrameLayout>
一个资源文件
attrs.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="FlowIndicator"> <attr name="count" format="integer" /> <attr name="space" format="dimension" /> <attr name="point_size" format="dimension" /> <attr name="point_seleted_color" format="color|reference" /> <attr name="point_normal_color" format="color|reference" /> <attr name="point_radius" format="dimension" /> </declare-styleable> </resources>FlowIndicator.java
public class FlowIndicator extends View { private int count; private float space, radius; private int point_normal_color, point_seleted_color; // 选中 private int seleted = 0; public FlowIndicator(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub //提供TypedArray(用于Drawable对象数组)的XML资源。 TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.FlowIndicator); count = typedArray.getInteger(R.styleable.FlowIndicator_count,4); space = typedArray.getDimension(R.styleable.FlowIndicator_space, 9); radius = typedArray.getDimension(R.styleable.FlowIndicator_point_radius, 9); point_normal_color = typedArray.getColor(R.styleable.FlowIndicator_point_normal_color, 0x000000); point_seleted_color = typedArray.getColor(R.styleable.FlowIndicator_point_seleted_color, 0xffff07); int sum = attrs.getAttributeCount(); if(Constans.DEBUG){ String str = ""; for(int i=0;i<sum;i++){ String name = attrs.getAttributeName(i); String value = attrs.getAttributeValue(i); str += "sttr_name:" + name +": " + value +"\n"; } Log.i("attribute", str); } typedArray.recycle(); } public void setSeletion(int index){ this.seleted = index; //重绘 invalidate(); } public void setCount(int count){ this.count = count; invalidate(); } public void next(){ if(seleted < count-1){ seleted++; }else{ seleted = 0; } invalidate(); } public void previous(){ if(seleted > 0 ){ seleted--; }else{ seleted = count-1; } invalidate(); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); Paint paint = new Paint(); paint.setAntiAlias(true); float width = (getWidth() - ((radius * 2 * count) + (space * (count - 1))))/2.f; for (int i = 0; i < count; i++) { if (i == seleted) paint.setColor(point_seleted_color); else paint.setColor(point_normal_color); canvas.drawCircle(width + getPaddingLeft() + radius + i * (space + radius + radius), getHeight() / 2, radius, paint); } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); } private int measureWidth(int measureSpec) { int result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == MeasureSpec.EXACTLY) { result = specSize; } else { result = (int) (getPaddingLeft() + getPaddingRight() + (count * 2 * radius) + (count - 1) * radius + 1); if (specMode == MeasureSpec.AT_MOST) { result = Math.min(result, specSize); } } return result; } private int measureHeight(int measureSpec) { int result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == MeasureSpec.EXACTLY) { result = specSize; } else { result = (int) (2 * radius + getPaddingTop() + getPaddingBottom() + 1); if (specMode == MeasureSpec.AT_MOST) { result = Math.min(result, specSize); } } return result; } }MainActivity.java
public class MainActivity extends Activity { private static final int SCROLL_ACTION = 0; private TextView textView; private Gallery mGallery; private FlowIndicator myView; Timer mTimer; private GalleryAdapter galleryAdapter; private String[] titles = {"标题1","标题2","标题3","标题4","标题5","标题6","标题7","标题8","标题9"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.header_view); viewInit(); //定时滚动 mTimer = new Timer(); mTimer.scheduleAtFixedRate(new MyTask(), 0, 5000); } private void viewInit(){ textView = (TextView) findViewById(R.id.tv_gal_title); mGallery = (Gallery) findViewById(R.id.home_gallery); myView = (FlowIndicator) findViewById(R.id.myview); galleryAdapter = new GalleryAdapter(this); myView.setCount(galleryAdapter.getCount()); mGallery.setAdapter(galleryAdapter); mGallery.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub textView.setText(titles[arg2]); myView.setSeletion(arg2); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); } private class GalleryAdapter extends BaseAdapter{ Context mContext; int[] res = new int[] { R.drawable.t1, R.drawable.t2, R.drawable.t3, R.drawable.t1, R.drawable.t2, R.drawable.t3, R.drawable.t1, R.drawable.t2, R.drawable.t3 }; public GalleryAdapter(Context cnt) { this.mContext = cnt; } @Override public int getCount() { // TODO Auto-generated method stub return res.length; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return res[arg0]; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return arg0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView == null){ convertView = LayoutInflater.from(mContext).inflate(R.layout.gallery_item, null); } ImageView imageView = (ImageView) convertView.findViewById(R.id.home_img); imageView.setImageResource(res[position]); return convertView; } } private class MyTask extends TimerTask { @Override public void run() { mHandler.sendEmptyMessage(SCROLL_ACTION); } } Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); switch (msg.what) { case SCROLL_ACTION: MotionEvent e1 = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 89.333336f, 265.33334f, 0); MotionEvent e2 = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 300.0f, 238.00003f, 0); mGallery.onFling(e1, e2, -1300, 0); break; default: break; } } }; }Constans.java
public class Constans { public static boolean DEBUG = true; }
相关推荐
And then you'll need to connect your ViewFlow with the FlowIndicator: CircleFlowIndicator indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic); viewFlow.setFlowIndicator(indic); By default,...
38 -设备部经理绩效考核表1
在做了充分的需求分析之后,将一站式电脑配件交易平台的需求分为商品管理、订单管理、配送管理、组装管理和评论管理等多个子模块,随后对系统进行设计,设计主要从系统整体架构和数据库两方面进行分析和设计,系统的核心功能主要包括商品管理、订单管理、配送管理、组装管理和评论管理,而非核心功能主要包含了用户管理和用户登录管理等模块。而后,对系统进行了编码并实现了所有功能,最后,对系统相关功能展开测试,并通过了系统测试,充分验证了系统可用性。
数据名称:2000-2022年各县市区主要社会经济发展指标面板数据 数据类型:dta格式 数据来源:中国县域统计
内容概要:本文提供了针对大学生英语竞赛写作准备的重要资源——一系列通用的英文句子模板。这些模板涵盖了现代经济社会的各种话题,从科技进步到环境保护,以及个人品质和社会责任等,并且适用于论述类文章、观点对比和个人见解的表达。文章通过对每一句话的应用环境解释和语法提示,确保使用者可以在实际写作中正确且有效地应用这些表达方式。 适合人群:正在准备参加大学生英语竞赛的学生及其他希望提高书面表达能力的学习者。 使用场景及目标:考生能够在竞赛时间内迅速构建思路完整的文章,增强语言表达的流利性和规范性;帮助学习者积累高级词汇,提升英语写作水平并培养良好的思维逻辑。 阅读建议:结合历年优秀范文进行深入学习,熟悉不同类型话题下的表述方法;练习将提供的句子融入自身创作的文章中,通过不断修订和完善来巩固记忆。同时也可以用于日常的英语写作训练当中。
本代码参考网络大神代码以及结合自身理解,编写的关于使用STM32F103C8T6芯片,通过ESP8266模块,连接阿里云物联网平台的代码历程,文件内包含了如何修改代码连接自己的设备的教程(readme.txt)文件,请读者仔细阅读。
宽带折叠传输阵天线.pdf
这是一个exe程序,解压后可以批量将Word文件转为PDF文件。
09 -单证部经理绩效考核表1
2009-2022年农村金融发展水平省级面板数据 31省份金融发展水平数据(不含港澳台地区) 涉农贷款金额亿元/第一产业增加值 30省份第一产业产值(2009-2022年) 30省份农业金融发展水平(2009-2022年)
2022年9月全国大学生英语竞赛A类初赛参考答案
Python源码03之解决对图片格式进行批量转换的问题.zip
病毒
基于向量特征的车辆轨迹预测.pdf
10-15-物控人员绩效考核表(自动计算、等级评价、任意设置)
员工末位淘汰考评表
1、操作简单,导入(待分班的数据xlsx格式),分班、导出三步。 2、分班条件设置:可选科类组合,设置起始班级和学生预设班级。 3、分班结果:班级人数均衡、男女均衡,各科成绩和总分班级均衡,最大分差不超过0.5分。 4、导出xlsx格式的分班结果。含各班单独的工作表和统计数据表。
人事档案登记及查询系统
第3课《安塞腰鼓》课件-语文八年级下册
C语言之考勤模拟系统平台(千行代码)