引导页[文字动态出来]
来源:互联网 发布:java面向对象编程思想 编辑:程序博客网 时间:2024/04/27 19:43
示例工程[附工程代码]
一:效果及介绍
1.每个引导页里有一张背景图片,有个文字序列,并且文字是逐行显示出来的.
2. 底部的指示器是可以动态变化的,根据图片的多少决定总数,选中那个就会变亮。
3.适配器可以自动滑动。
二:实现思路
a)实现引导页,肯定要使用v4包里的ViewPager组件。根据现在的效果,item子组件由一个ImageView[图片]和四个TextView组成,四个TextView要相互错开,且每个TextView一行只能显示一个字。
b)实现指示器,就是那一堆小点。实现原理就是继承LinearLayout,根据用户设置的总数,决定创建几个子ImageView出来,设置了选中点后,把对应子view的背景图片置为选中,其它子view置成正常背景。只需要自定义个组件即可。
c)文字动态飞出来的效果,到对应页面后,发延迟消息,收到消息在发消息,逐步把四个TextView里的文本展示出来。
三:关键代码分析
a) 主界面布局 guider_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GuideMainActivity" >
<android.support.v4.view.ViewPager
android:id="@+id/view_guide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
/>
<com.lyg.guide.view.GuidePointLayout
android:id="@+id/guider_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
/>
</RelativeLayout
b)item的配置文件 guider_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
>
<ImageView
android:id="@+id/iv_guide"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
/>
<TextView
android:id="@+id/tv_info1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:textSize="16sp"
/>
<TextView
android:id="@+id/tv_info2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/tv_info1"
android:ems="1"
android:layout_marginLeft="10dp"
android:layout_marginTop="40dp"
android:textSize="16sp"
/>
<TextView
android:id="@+id/tv_info3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/tv_info2"
android:ems="1"
android:layout_marginLeft="10dp"
android:layout_marginTop="60dp"
android:textSize="16sp"
/>
<TextView
android:id="@+id/tv_info4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/tv_info3"
android:ems="1"
android:layout_marginLeft="10dp"
android:layout_marginTop="70dp"
android:textSize="20sp"
/>
</RelativeLayout>
c)自定义的指示器实现
/**
* @author luyg
* @function: 指示小圆点,可动态添加
*/
public class GuidePointLayout extends LinearLayout {
private int count ;
private int marginRight = 0;
private int normalId = R.drawable.launcher_point_n;
private int selectId = R.drawable.launcher_point_s;
private int selectIndex =0 ;
public GuidePointLayout(Context context) {
super(context);
}
public GuidePointLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GuidePointLayout(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
/**
* @param count : 指示点的总数
* @param marginRight : 指示点的右间距
*/
public void init(int count , int marginRight ){
this.count =count;
this.marginRight = marginRight ;
initViews();
selectPoint(0);
}
private void initViews(){
for (int i = 0; i < count; i++) {
ImageView imageView = new ImageView(getContext());
imageView.setImageResource(normalId);
ViewGroup.LayoutParams layoutParams =new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT ,
ViewGroup.LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(layoutParams);
imageView.setPadding(0, 0, marginRight, 0);
this.addView(imageView);
}
}
public void selectPoint(int index){
if (index<=0 || index>=getChildCount()) {
//correnct error index
selectIndex = 0;
}else {
selectIndex = index ;
}
for(int i = 0 ; i<getChildCount() ; i++){
if (i==selectIndex) {
((ImageView)getChildAt(i)).setImageResource(selectId);
}else {
((ImageView)getChildAt(i)).setImageResource(normalId);
}
}
}
/**
* @function: 指示点右移动
*/
public void increase(){
((ImageView)getChildAt(selectIndex)).setImageResource(normalId);
selectIndex++;
if (selectIndex>=getChildCount()) {
selectIndex=getChildCount()-1;
}
((ImageView)getChildAt(selectIndex)).setImageResource(selectId);
}
/**
* @function: 指示点左移动
*/
public void decrease(){
((ImageView)getChildAt(selectIndex)).setImageResource(normalId);
selectIndex--;
if (selectIndex<0) {
selectIndex=0;
}
((ImageView)getChildAt(selectIndex)).setImageResource(selectId);
}
}
d) ViewPager及适配器的实现就不贴代码了,网上示例很多。
- 引导页[文字动态出来]
- Android之动态引导页
- app动态引导页的制作
- Android之ViewPager引导页(动态加载指示器)
- Android 引导页动态添加圆点指示器
- 自定义启动页(包括:静态页,动态页,广告页,向导页,自动滚动页) 自定义引导页 (包括: 传统引导页,浮层动画引导,gif引导页,自定义引导页,视频引导页)
- 把图片中的文字抠出来
- 怎么把PDF中的文字提取出来
- css3中文字“走”出来的效果
- js控制文字一个一个的显示出来
- Android实现文字一个一个显示出来
- Android实现文字逐字显示出来效果
- android 引导图 动态背景
- 引导页
- 引导页
- 引导页
- 引导页
- 引导页
- Android 屏幕适配方案
- OSI七层模型的排序及各层的相应的应用有哪些?
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- 项目中使用Quartz集群分享--http://hot66hot.iteye.com/blog/1726143
- c++反转整个链表
- 引导页[文字动态出来]
- StrictMode 详解
- fork()函数
- Java中的||和&&
- 随机产生24个数字,且就24个数字
- Android视图状态及重绘流程分析,带你一步步深入了解View(三)
- win 10 使用本地代理自动配置pac
- get_transform is not allowed to be called from a MonoBehaviour constructor (or instance field initia
- zepto 操作 cookie