******************************本人小白***************************
学习前人
总体思路:一共是两个Activity ,一个是展示引导界面,另一个就是展示界面进入后的活动窗体。
1、引导界面共有三张图片,放在资源文件夹下,@drawable/*,在主界面使用ViewFlipper 控件,在该控件的内加入线性布局,其中在第三个线性布局中加入Button按钮,点击后进入活动窗体。
2、写活动窗体的源代码
引导界面
<LinearLayout 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:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ViewFlipper
android:id="@+id/ViewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="18" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sheldon1" >
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sheldon2" >
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sheldon3" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="18"
android:text="@string/login" />
</FrameLayout>
</ViewFlipper>
<RadioGroup
android:id="@id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="5"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/radioButton1"
android:checked="true"
android:enabled="false"
/>
<RadioButton
android:id="@+id/radioButton2"
android:enabled="false"
/>
<RadioButton
android:id="@+id/radioButton3"
android:enabled="false"
/>
</RadioGroup>
</LinearLayout>
活动界面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textSize="14dp"
android:text="Hello Android"
android:gravity="center"
/>
</LinearLayout>
主界面代码
package com.example.welcome;
import android.app.Activity;
import android.content.Intent;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ViewFlipper;
public class MainActivity extends Activity implements OnGestureListener{
private ViewFlipper viewFlipper;
private GestureDetector detector;
private RadioGroup rGroup;
private RadioButton rButton1;
private RadioButton rButton2;
private RadioButton rButton3;
private Button button1;
private int temp;
private RadioButton rs[]=new RadioButton[3];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper=(ViewFlipper)findViewById(R.id.ViewFlipper);
detector=new GestureDetector(this);
rButton1=(RadioButton)findViewById(R.id.radioButton1);
rButton2=(RadioButton)findViewById(R.id.radioButton2);
rButton3=(RadioButton)findViewById(R.id.radioButton3);
rs[0]=rButton1;
rs[1]=rButton2;
rs[2]=rButton3;
button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent=new Intent(MainActivity.this,welcome.class);
startActivity(intent);
MainActivity.this.finish();
}
});
}
private ImageView getImageView(int id) {
ImageView imageView = new ImageView(this);
imageView.setImageResource(id);
return imageView;
}
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
}
public boolean onDown(MotionEvent e) {
return false;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > 120) {
viewFlipper.showNext();
temp++;
rs[temp].setChecked(true);
return true;
} else if (e1.getX() - e2.getY() < -120) {
viewFlipper.showPrevious();
temp--;
rs[temp].setChecked(true);
return true;
}
return false;
}
public void onLongPress(MotionEvent e) {
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
return false;
}
public void onShowPress(MotionEvent e) {
}
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
}
活动界面的代码
package com.example.welcome;
import android.app.Activity;
import android.os.Bundle;
public class welcome extends Activity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
}
}
以上这些亲测可用。