Android毕设点滴の过度ページ(一)
5107 ワード
前言:
移行ページの重要性は、KFCで並んで食べ物を買うことに相当し、並んでいるうちに「今日は何を食べますか?」と思うかもしれません.
この移行の一環を除けば、少し友好的ではないかもしれません.2つ目は、移行ページに広告を植え込むことができます.
プロジェクト構造
//元々必要なページのロード後、別のページのロード
//だからまず考えたのはAsyncTask非同期スレッド
//BackgroundLoadableを作成する目的は、インスタンス化されたプロセスをその実装クラスに遅延することである.
遷移ページxml
interface BackgroundLoadable
LoadMainInBackgroundTask
MainActivity
移行ページの重要性は、KFCで並んで食べ物を買うことに相当し、並んでいるうちに「今日は何を食べますか?」と思うかもしれません.
この移行の一環を除けば、少し友好的ではないかもしれません.2つ目は、移行ページに広告を植え込むことができます.
プロジェクト構造
//元々必要なページのロード後、別のページのロード
//だからまず考えたのはAsyncTask非同期スレッド
//BackgroundLoadableを作成する目的は、インスタンス化されたプロセスをその実装クラスに遅延することである.
遷移ページxml
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_weight="1.0"
android:visibility="gone" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<LinearLayout
android:id="@+id/welcomelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<ImageView
android:contentDescription="@string/contentDescription"
android:id="@+id/MainActivity_Image"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/welcome"
android:textSize="20sp" />
<TextView
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/app_name"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="10dp"
android:text="@string/copyright"
android:textAppearance="?android:attr/textAppearanceSmall" >
</TextView>
</TabHost>
interface BackgroundLoadable
public interface BackgroundLoadable{
public void onPreLoad();
public View loadInBackground();
public void onPostLoad(View view);
}
LoadMainInBackgroundTask
public class LoadMainInBackgroundTask extends AsyncTask<Void,Object,View>{
BackgroundLoadable activity;
int minLoadTime;
public LoadMainInBackgroundTask(BackgroundLoadable activity,int minLoadTime){
this.activity = activity;
this.minLoadTime = minLoadTime;
}
protected void onPreExecute()
{
activity.onPreLoad();
}
@Override
protected View doInBackground(Void... params)
{
// .
long time1 = System.currentTimeMillis();
View view = activity.loadInBackground();
long time2 = System.currentTimeMillis();
if ((time2 - time1) < minLoadTime) {
try {
Thread.sleep(minLoadTime - (time2 - time1));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return view;
}
@Override
protected void onPostExecute(View result)
{
activity.onPostLoad(result);
}
}
MainActivity
public class MainActivity extends Activity implements BackgroundLoadable{
protected final int SPLASH_TIME = 2000;
private ImageView imageView;
private LoadMainInBackgroundTask task;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
setTransitionPage();
task = new LoadMainInBackgroundTask(this, SPLASH_TIME);
task.execute();
}
private void setTransitionPage(){
imageView = (ImageView) findViewById(R.id.MainActivity_Image);
imageView.setImageResource(R.drawable.ic_launcher);
}
@Override
public void onPreLoad() {
}
@Override
public View loadInBackground() {
// TODO Auto-generated method stub
return getLayoutInflater().inflate(R.layout.activity_main, null);
}
@Override
public void onPostLoad(View view) {
// TODO Auto-generated method stub
setContentView(view);
}
}