package com.example.administrator.test1; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.bumptech.glide.Glide; public class TGsplashActivity extends Activity { ImageView banner; TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gsplash); banner= (ImageView) findViewById(R.id.banner_view); tv= (TextView)findViewById(R.id.tv_jump); initView(); initglide(); banner.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Toast.makeText(TGsplashActivity.this, "点击加载的图片", Toast.LENGTH_LONG).show(); } }); } private void initglide(){ if(isNetworkAvailable(this)){ Glide.with(TGsplashActivity.this).load(this.getString(R.string.urlinfo)).placeholder(R.mipmap.splashs) .error(R.mipmap.splashs).centerCrop().into(banner); } else{ Toast.makeText(this,"请求网络失败",Toast.LENGTH_LONG).show(); Glide.with(TGsplashActivity.this).load(R.mipmap.splashs).centerCrop().into(banner); } } private void initView() { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { tv.setVisibility(View.VISIBLE); Thread t = new Thread(new JumpThreadT(tv,3,TGsplashActivity.this)); t.start(); } }, 1000); } /** * 检测当的网络(WLAN、3G/2G)状态 * @param context Context * @return true 表示网络可用 */ public boolean isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.isConnected()) { // 当前网络是连接的 if (info.getState() == NetworkInfo.State.CONNECTED) { // 当前所连接的网络可用 return true; } } } return false; } public class JumpThreadT implements Runnable { private TextView textView; private int numberTime ; private Activity activity; public JumpThreadT(TextView textView, int numberTime, Activity activity) { this.textView = textView; this.numberTime = numberTime; this.activity = activity; } Handler handler =new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); //textView.setText("跳转 "+ String.valueOf(numberTime)); String tz=activity.getString(R.string.tiaozhuan); textView.setText(tz+" " +String.valueOf(numberTime)); if (numberTime==0) { jumpActivity(); } } }; private void jumpActivity(){ Intent intent = new Intent(activity, GuideActivity.class); activity.startActivity(intent); //activity切换动画 activity.overridePendingTransition(R.anim.screen_zoom_in, R.anim.screen_zoom_out); activity.finish(); } @Override public void run() { try { while (numberTime>0) { Thread.sleep(1000); numberTime--; handler.sendMessage(new Message()); } } catch (InterruptedException e) { e.printStackTrace(); } } } }
xml文件
<RelativeLayout 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" > <ImageView android:id="@+id/banner_view" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ImageView> <TextView android:id="@+id/tv_jump" android:layout_width="70dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="30dp" android:layout_marginTop="40dp" android:background="@drawable/shape_jump" android:gravity="center" android:textColor="#fff" android:textSize="16sp" android:visibility="gone" android:text="跳过 3"/> <ImageView android:id="@+id/iv_default" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>