目前市场上的应用有几个比较使用频繁的功能
(1)引导页:包括Welcome页面和Guide页面。
(2)TabHost的使用。
(3)侧边栏的使用。
(1)下拉ListView或者ScrollView刷新。
引导页
1.Welcome页面
这个应该是最简单的,常规想法是定义一个ImageView充满屏幕即可,但是要注意一个问题,当点击进入的时候会先闪一下黑屏或者白屏(这个得看定义的主题背景)。
解决方式是定义一个activity的style,里面包含窗口背景即为Welcome页面的背景图片,如下:
<style name="WelcomeActivtyTheme" parent="@style/AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@drawable/welcome_bg</item>
</style>
然后WelcomeActivity在manifast中引用即可。
<activity
android:name="com.cartoon.WelcomeActivity"
android:theme="@style/WelcomeActivtyTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2.Guide页面
这个也很简单,只需要使用ViewPager即可,这个不需要多说。我在使用ViewPager的时候自定义一个IndicatorContainer配合使用,移动到那个页面,指引到哪个点。
直接贴出IndicatorContainer的代码。
package com.common.view;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
public class IndicatorContainer extends LinearLayout {
private OnIndicatorSelectedListener mIndicatorSelectedListener;
public IndicatorContainer(Context context) {
super(context);
}
public IndicatorContainer(Context context, AttributeSet attrs) {
super(context, attrs);
}
@SuppressLint("NewApi")
public IndicatorContainer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
private View.OnClickListener mChildOnClickListener = new OnClickListener() {
@Override
public void onClick(View view) {
setIndicatorSelected(view);
notifyIndicatorSelected(view);
}
};
@Override
protected void onFinishInflate() {
super.onFinishInflate();
int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
child.setOnClickListener(mChildOnClickListener);
}
}
public void setOnIndicatorSelectedListener(OnIndicatorSelectedListener l) {
mIndicatorSelectedListener = l;
}
public void setIndicatorSelected(int position) {
setIndicatorSelected(getChildAt(position));
}
private void setIndicatorSelected(View view) {
int index = indexOfChild(view);
int count = getChildCount();
if (index >= 0 && index < count) {
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
child.setSelected(index == i);
}
}
}
private void notifyIndicatorSelected(View view) {
int index = indexOfChild(view);
int count = getChildCount();
if (index >= 0 && index < count && mIndicatorSelectedListener != null) {
mIndicatorSelectedListener.onIndicatorSelected(view, index);
}
}
public void addIndicator(View view) {
if (view != null) {
view.setOnClickListener(mChildOnClickListener);
addView(view);
}
}
public interface OnIndicatorSelectedListener {
public void onIndicatorSelected(View view, int position);
}
}