其他方式登录控件

先看效果图,很简单的控件,不需要自定义:
这里写图片描述

分析一下要点:

  1. 点击后,屏幕会有变暗,有一层遮罩
  2. 整块布局有个上下移动的动画
  3. 未点击状态下,布局往下移动了距离

    布局文件:

<?xml version="1.0" encoding="utf-8"?>
<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"
                android:fitsSystemWindows="true"
                android:background="@mipmap/grsm">

    <android.support.v7.widget.CardView
        android:layout_width="300dp"
        android:layout_height="340dp"
        app:cardCornerRadius="6dp"
        app:cardElevation="3dp"
        app:cardUseCompatPadding="true"
        android:layout_centerInParent="true"
        android:id="@+id/cv">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
        >
            <RelativeLayout
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="45dp">
                <View
                    android:layout_alignParentStart="true"
                    android:layout_width="8dp"
                    android:layout_height="match_parent"
                    android:background="#2fa881"
                />
                <TextView
                    android:layout_centerVertical="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="50dp"
                    android:text="登录"
                    android:textColor="#FFCC00"
                    android:textSize="18sp"
                    android:textStyle="bold"
                />
            </RelativeLayout>
            <LinearLayout
                android:layout_marginTop="10dp"
                android:paddingStart="50dp"
                android:paddingEnd="30dp"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="50dp">
                <android.support.design.widget.TextInputLayout
                    android:textColorHint="#c5c5c5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <EditText
                        android:textSize="13sp"
                        android:hint="用户名"
                        android:textColor="#2fa881"
                        android:id="@+id/et_username"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textPersonName"
                        android:background="@drawable/selector_bg_edit"
                        android:textCursorDrawable="@drawable/bg_input_cursor"
                        android:paddingBottom="2dp"
                    />
                </android.support.design.widget.TextInputLayout>
            </LinearLayout>
            <LinearLayout
                android:paddingStart="50dp"
                android:paddingEnd="30dp"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="50dp">
                <android.support.design.widget.TextInputLayout
                    android:textColorHint="#c5c5c5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <EditText
                        android:textSize="13sp"
                        android:hint="密码"
                        android:textColor="#2fa881"
                        android:id="@+id/et_password"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textPassword"
                        android:background="@drawable/selector_bg_edit"
                        android:textCursorDrawable="@drawable/bg_input_cursor"
                        android:paddingBottom="2dp"
                    />
                </android.support.design.widget.TextInputLayout>
            </LinearLayout>
            <RelativeLayout
                android:layout_marginTop="25dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="60dp">
                <Button
                    android:id="@+id/bt_go"
                    android:background="@drawable/bt_shape"
                    android:stateListAnimator="@drawable/state_list_animator_z"
                    android:layout_width="150dp"
                    android:layout_height="50dp"
                    android:text="@string/go"
                    android:textColor="#d3d3d3"
                >
                </Button>
            </RelativeLayout>
            <TextView
                android:layout_marginTop="5dp"
                android:layout_gravity="center_horizontal"
                android:textColor="#9a9a9a"
                android:textSize="12sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/forgot_your_password"
            />
        </LinearLayout>
    </android.support.v7.widget.CardView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="normal"
        android:src="@drawable/plus"
        android:transitionName="loginFab"
        android:layout_alignTop="@id/cv"
        android:layout_marginTop="25dp"
        android:layout_alignEnd="@id/cv"
        android:layout_marginEnd="-20dp"
    />

    //增加整块布局盖在上面,用来增加盖层
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        //盖层灰度:"#80000000"   android:alpha="0"为未点击状态下
        <View
            android:id="@+id/ll_login_layer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0"
            android:background="#80000000" />

        //将 点击 布局 整体往下偏移80dp
        <LinearLayout
            android:id="@+id/ll_login_pull"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@drawable/bg_login_thirdpart"
            android:orientation="vertical"
            android:translationY="80dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="12dp"
                android:gravity="center"
                android:text="其他方式登录"
                android:textColor="#cacaca"
                android:textSize="14sp" />

            <LinearLayout
                android:id="@+id/ll_login_options"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:orientation="horizontal"
                android:paddingBottom="16dp"
                android:visibility="visible">


                <ImageView
                    android:id="@+id/ib_login_weibo"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/ic_material"
                    android:contentDescription="@null"
                    android:padding="8dp"
                    android:scaleType="centerInside"
                    android:src="@mipmap/ic_login_3party_weibo" />

                <ImageView
                    android:id="@+id/ib_login_wx"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/ic_material"
                    android:contentDescription="@null"
                    android:padding="8dp"
                    android:scaleType="centerInside"
                    android:src="@mipmap/ic_login_3party_wechat" />

                <ImageView
                    android:id="@+id/ib_login_qq"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/ic_material"
                    android:contentDescription="@null"
                    android:padding="8dp"
                    android:scaleType="centerInside"
                    android:src="@mipmap/ic_login_3party_qq" />

                <ImageView
                    android:id="@+id/ib_login_csdn"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/ic_material"
                    android:contentDescription="@null"
                    android:padding="8dp"
                    android:scaleType="centerInside"
                    android:src="@mipmap/ic_login_3party_csdn" />
            </LinearLayout>
        </LinearLayout>


    </FrameLayout>

</RelativeLayout>

布局只做了2点:增加盖层,点击布局下移80dp

代码的实现部分:
点击事件

//点击监听
case R.id.ll_login_pull:
                llLoginPull.animate().cancel();//点击区域的动画取消
                llLoginLayer.animate().cancel();//盖层区域的动画取消

                int height = llLoginOptions.getHeight();//拿到未显示区域的高度80dp
                //拿到当前动画进度 llLoginLayer会在动画执行的时候动态设置tag
                float progress = (llLoginLayer.getTag() != null && llLoginLayer.getTag() instanceof Float) ?
                        (float) llLoginLayer.getTag() : 1;
                 //动画执行时间,360为动画时间0.36s,慢点就跳大,快点就调小
                int time = (int) (360 * progress);
                //判断布局已经显示或者未显示 执行响应操作
                if (llLoginPull.getTag() != null) {
                    llLoginPull.setTag(null);
                    glide(height, progress, time);
                } else {
                    llLoginPull.setTag(true);
                    upGlide(height, progress, time);
                }
                break;

* 上升动画,显示盖层*

 /**
     * menu up glide
     *
     * @param height   height
     * @param progress progress
     * @param time     time
     */
    private void upGlide(int height, float progress, int time) {
        llLoginPull.animate()
                .translationYBy(height * progress)
                .translationY(0)
                .setDuration(time)
                .start();
        llLoginLayer.animate()
                .alphaBy(1 - progress)
                .alpha(1)
                .setDuration(time)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        llLoginLayer.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        if (animation instanceof ValueAnimator) {
                        //设置tag,值为动画的参数
                            llLoginLayer.setTag(((ValueAnimator) animation).getAnimatedValue());
                        }
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (animation instanceof ValueAnimator) {
                        //设置tag,值为动画的参数
                            llLoginLayer.setTag(((ValueAnimator) animation).getAnimatedValue());
                        }
                    }
                })
                .start();
    }

* 下降动画,隐藏盖层*

 /**
     * menu up glide
     *
     * @param height   height
     * @param progress progress
     * @param time     time
     */
    private void upGlide(int height, float progress, int time) {
        llLoginPull.animate()
                .translationYBy(height * progress)
                .translationY(0)
                .setDuration(time)
                .start();
        llLoginLayer.animate()
                .alphaBy(1 - progress)
                .alpha(1)
                .setDuration(time)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        llLoginLayer.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        if (animation instanceof ValueAnimator) {
                            llLoginLayer.setTag(((ValueAnimator) animation).getAnimatedValue());
                        }
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (animation instanceof ValueAnimator) {
                            llLoginLayer.setTag(((ValueAnimator) animation).getAnimatedValue());
                        }
                    }
                })
                .start();
    }

基本可以实现上面动画效果了,很简单实用

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用ASP.NET Login控件可以方便地实现用户登录功能,但是并不包括用户注册功能。因此,在实现用户注册和登录的过程中,需要使用其他控件和技术。 一般情况下,实现用户注册功能需要使用ASP.NET的用户管理工具(Membership)和角色管理工具(RoleManager),它们提供了一些API,可以方便地实现用户注册、登录、密码找回等功能。下面是一个简单的实现用户注册和登录的过程: 1. 配置Web应用程序的身份验证方式为“表单身份验证”。 2. 在Web.config文件中配置Membership和RoleManager: ```xml <system.web> <membership defaultProvider="AspNetSqlMembershipProvider"> <providers> <clear /> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" /> </providers> </membership> <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider"> <providers> <clear /> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" /> </providers> </roleManager> </system.web> ``` 3. 在Web页面中添加Login控件和CreateUserWizard控件,分别用于用户登录和注册: ```html <asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Default.aspx"></asp:Login> <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" CreateUserButtonText="注册" ContinueDestinationPageUrl="~/Default.aspx"> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"> <ContentTemplate> <table> <tr> <td>用户名:</td> <td><asp:TextBox ID="UserName" runat="server"></asp:TextBox></td> <td><asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator></td> </tr> <tr> <td>密码:</td> <td><asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox></td> <td><asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator></td> </tr> <tr> <td>确认密码:</td> <td><asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox></td> <td><asp:CompareValidator ID="ConfirmPasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" ErrorMessage="两次输入的密码不一致"></asp:CompareValidator></td> </tr> <tr> <td>Email:</td> <td><asp:TextBox ID="Email" runat="server"></asp:TextBox></td> <td><asp:RegularExpressionValidator ID="EmailRegularExpression" runat="server" ControlToValidate="Email" ErrorMessage="Email格式不正确" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td> </tr> </table> </ContentTemplate> </asp:CreateUserWizardStep> </WizardSteps> </asp:CreateUserWizard> ``` 4. 在代码中处理用户登录和注册: ```csharp protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 如果已经登录,则跳转到主页 if (User.Identity.IsAuthenticated) { Response.Redirect("~/Default.aspx"); } } } protected void Login1_LoggedIn(object sender, EventArgs e) { // 用户登录成功后的处理 Response.Redirect("~/Default.aspx"); } protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { // 用户注册成功后的处理 Response.Redirect("~/Default.aspx"); } ``` 以上代码仅为示例,实际的实现过程可能会更加复杂。在实际开发中,还需要考虑用户密码加密、用户信息存储等问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值