Android模仿新浪微博(启动界面&登陆界面)

启动界面

主要有两个功能:
1.加载启动动画
2.判断网络,有者直接进入登陆界面,否则去设置网络

代码较简单,主要采用AlphaAnimation()方法和动画监听器,使一张图片产生渐变动画。在动画启动的时候判断网络,动画结束时完成判断并进入登陆界面。

/**
 * Created by D&LL on 2016/5/25.
 * 初始页面加载界面
 */
public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        ImageView splashimage = (ImageView) findViewById(R.id.splashimage);
        //透明度渐变动画
        AlphaAnimation animation = new AlphaAnimation(0.1f, 1.0f);
        //设置动画时长
        animation.setDuration(3000);
        //将组件和动画进行关联
        splashimage.setAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            //动画启动执行
            @Override
            public void onAnimationStart(Animation animation) {
                Toast.makeText(SplashActivity.this, "欢迎使用DeMon制作微博", Toast.LENGTH_LONG).show();
                //检查并网络的方法
                Tools.checkNetWork(SplashActivity.this);
            }

            //动画结束执行
            @Override
            public void onAnimationEnd(Animation animation) {
                Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }

            //动画重复执行
            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }

使用ConnectivityManager获取系统的连接服务,然后获取代表联网状态的NetWorkInfo对象,获取网络的连接情况,如果没有网络则生成一个AlertDialog引导进行网络设置。该方法位于Tools.java中。

 /**
     * 设置网络
     *
     * @param context
     */
    public static void checkNetWork(final SplashActivity context) {
        if (!NetWorkStatus(context)) {
            TextView msg = new TextView(context);
            msg.setText("请设置网络!");
            AlertDialog.Builder b = new AlertDialog.Builder(context).
                    setIcon(R.drawable.notnet)
                    .setTitle("没有可用的网络")
                    .setMessage("是否对网络进行设置?");
            b.setPositiveButton("是", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    //跳转到设置网络界面
                    context.startActivity(new Intent(Settings.ACTION_SETTINGS));
                }
            }).setNeutralButton("否", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                    context.finish();
                }
            }).create().show();
        }
    }

    /**
     * 判断网络状态
     */
    public static boolean NetWorkStatus(Context context) {
        //获取系统的连接服务
        ConnectivityManager connect = (ConnectivityManager) context.getSystemService(Context
                .CONNECTIVITY_SERVICE);
        if (connect == null) {
            return false;
        } else {
            // 获取代表联网状态的NetWorkInfo对象,获取网络的连接情况
            NetworkInfo[] infos = connect.getAllNetworkInfo();
            if (infos != null) {
                for (NetworkInfo network : infos) {
                    if (network.getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

SplashActivity的布局文件splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <ImageView
        android:id="@+id/splashimage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/splashimage"/>

    <ProgressBar
        style="@android:style/Widget.ProgressBar.Inverse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_gravity="center"
        android:layout_marginBottom="64dp"
        android:layout_marginStart="130dp">
    </ProgressBar>
</RelativeLayout>

这里写图片描述这里写图片描述

登陆界面

此界面只有几个按钮,故合在一条博客里。

微博按钮触发进入到到授权界面

public class LoginActivity extends Activity {
    private Button  sinalogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        sinalogin = (Button) findViewById(R.id.sinalogin);
        sinalogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this, OAuthActivity.class);
                startActivity(intent);
                LoginActivity.this.finish();
            }
        });
    }

}

布局文件login.xml两个自定义样式的EditText,一个普通按钮(此处纯粹摆设)。只有微博登陆按钮有用。

<?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:background="@drawable/background"
              android:gravity="center_vertical"
              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">

    <EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="40dip"
        android:background="@drawable/bg_edittext"
        android:ems="10"
        android:inputType="textPersonName">

    </EditText>

    <EditText
        android:id="@+id/passworld"
        android:layout_width="match_parent"
        android:layout_height="40dip"
        android:layout_marginTop="20dip"
        android:background="@drawable/bg_edittext"
        android:ems="10"
        android:inputType="textPassword"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/login"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip"
            android:layout_weight="1"
            android:text="登录"/>

        <Button
            android:id="@+id/sinalogin"
            android:layout_width="200dp"
            android:layout_height="38dp"
            android:layout_marginTop="20dip"
            android:layout_weight="1"
            android:background="@drawable/weibologin"/>
    </LinearLayout>
</LinearLayout>

这里写图片描述

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值