<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.example.dongmancheng.MainActivity"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="倒计时:2秒"
android:id="@+id/tv"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:visibility="gone"
android:id="@+id/image"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager"></android.support.v4.view.ViewPager>
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
private List<View> list=new ArrayList<View>();
private ViewPager pager;
private Button btn;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
int what=msg.what+1;
if (what<=1){
tv.setText("倒计时:"+(2-what)+"秒");
if (what==1){
Intent intent=new Intent(MainActivity.this,Main2.class);
startActivity(intent);
finish();
}
}
}
};
private TextView tv;
private ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.image);
tv = (TextView) findViewById(R.id.tv);
View v1=View.inflate(MainActivity.this,R.layout.layout1,null);
View v2=View.inflate(MainActivity.this,R.layout.layout2,null);
View v3=View.inflate(MainActivity.this,R.layout.layout3,null);
View v4=View.inflate(MainActivity.this,R.layout.layout4,null);
list.add(v1);
list.add(v2);
list.add(v3);
list.add(v4);
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new My());
btn = (Button) v4.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences sp=getSharedPreferences("info",MODE_PRIVATE);
sp.edit().putBoolean("first",true).commit();
Intent intent=new Intent(MainActivity.this,Main2.class);
startActivity(intent);
finish();
}
});
SharedPreferences sp=getSharedPreferences("info",MODE_PRIVATE);
boolean b = sp.getBoolean("first", false);
if (b){
pager.setVisibility(View.GONE);
tv.setVisibility(View.VISIBLE);
image.setVisibility(View.VISIBLE);
image.setImageResource(R.mipmap.ic_launcher);
new Thread(){
@Override
public void run() {
for (int i=0;i<2;i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(i);
}
}
}.start();
}
}
public void hou(){
SharedPreferences sp=getSharedPreferences("info",MODE_PRIVATE);
boolean b= sp.getBoolean("first", false);
new Thread(){
@Override
public void run() {
for (int i=0;i<2;i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(i);
}
}
}.start();
}
public void diciyi(){
SharedPreferences sp=getSharedPreferences("info",MODE_PRIVATE);
sp.edit().putBoolean("first",true).commit();
View v1=View.inflate(MainActivity.this,R.layout.layout1,null);
View v2=View.inflate(MainActivity.this,R.layout.layout2,null);
View v3=View.inflate(MainActivity.this,R.layout.layout3,null);
View v4=View.inflate(MainActivity.this,R.layout.layout4,null);
list.add(v1);
list.add(v2);
list.add(v3);
list.add(v4);
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new My());
btn = (Button) v4.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,Main2.class);
startActivity(intent);
finish();
}
});
}
class My extends PagerAdapter{
@Override
public int getCount() {
return list.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(list.get(position));
return list.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
}