一、开机启动页面SplashscreenActivity
启动页面很简单,总共就这么几个成员变量.效果为,Activity先setContentView,然后延迟2秒后,当前页面渐变动画,动画消失后,启动HomePage.
所谓的渐变效果的实现过程实际上是,Coding时先不考虑动画效果,先把静态的做出来,当静态的做好时,在把动画加上去。
二、HomeActivity
如图所示,主页面分两部分,上方为ViewFlipper,下方则是一个listview
1、ViewFliper
<com.teleca.jamendo.util.FixedViewFlipper
android:orientation="vertical" android:id="@+id/ViewFlipper"
android:layout_width="fill_parent" android:layout_height="75dip"
android:background="@drawable/gradient_dark_purple">
<!-- (0) Loading -->
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="15dip" android:gravity="left|center_vertical">
<com.teleca.jamendo.widget.ProgressBar
android:id="@+id/ProgressBar" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.teleca.jamendo.widget.ProgressBar>
</LinearLayout>
<!-- (1) Gallery -->
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center">
<Gallery android:id="@+id/Gallery" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:spacing="0px" />
</LinearLayout>
<!-- (2) Failure -->
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="15dip" android:gravity="left|center_vertical">
<com.teleca.jamendo.widget.FailureBar
android:id="@+id/FailureBar" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.teleca.jamendo.widget.FailureBar>
</LinearLayout>
</com.teleca.jamendo.util.FixedViewFlipper>
注意!ViewFlipper在android2.1以上版本存在BUG,需要自己重载重新写一个类,重载onDetachedFromWindow即可。
@Override
protected void onDetachedFromWindow() {
int apiLevel = Build.VERSION.SDK_INT;
if (apiLevel >= 7) {
try {
super.onDetachedFromWindow();
} catch (IllegalArgumentException e) {
Log.w("Jamendo", "Android project issue 6191 workaround.");
/* Quick catch and continue on api level 7, the Eclair 2.1 */
} finally {
super.stopFlipping();
}
} else {
super.onDetachedFromWindow();
}
}
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gestures"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gestureStrokeType="multiple"
android:eventsInterceptionEnabled="false" android:orientation="vertical">
<ListView android:id="@+id/HomeListView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:divider="#000" />
</android.gesture.GestureOverlayView>
由于需求为在主页面支持手势,故需要上述布局。
<com.teleca.jamendo.widget.ProgressBar
为一个Linearlayout,其中包括一个ProgressBar和一个TextView,采用inflate的方式将layout.xml合进来。
com.teleca.jamendo.widget.FailureBar也是一样。
3.1 launch方法,这样写的好处是,在任何一个地方启动该页面都是用的同一个flag,不会存在其他的变数,便于统一管理
一个应用的HomePage页面,启动的flag一定要设置为CLEAR_TOP!因为在主页时,按返回键是不可以在回到其他页面的。
public static void launch(Context c) {
Log.i(TAG, "============================HomeActivity launch!");
Intent intent = new Intent(c, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
c.startActivity(intent);
}
3.2OnCreate方法
此时,VIEW已经做好,需要加上Controler,在OnCreate中findAllViewById之后,变启动了一个asyncTask来获取并显示最新上线的专辑,取得数据
3.3OnResume方法
在这里显示主页面的ListView
这个ListView的adapter比较特殊。如图所以,中间有两行是不可以点击的,只是显示用的。乍一看是两个ListView,而实际上是一个。