xml地图|网站地图|网站标签 [设为首页] [加入收藏]

Android登陆页面仿拉钩动效,奇技淫巧之

来源:http://www.ccidsi.com 作者:集成经验 人气:173 发布时间:2020-03-01
摘要:作者们在开辟中时常会遇见软键盘遮挡住了输入框,而直接把输入框往上顶adjustResize这种艺术过于暴力影响雅观,我们意在键盘弹出时动态的去改换构造。那时候,便利用了监听键盘弹

作者们在开辟中时常会遇见软键盘遮挡住了输入框,而直接把输入框往上顶adjustResize这种艺术过于暴力影响雅观,我们意在键盘弹出时动态的去改换构造。那时候,便利用了监听键盘弹起风浪的功能。

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:andro android: android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:clipToPadding="true" android:background="@color/color_ffffff" android:orientation="vertical"> <ImageView android: android:layout_width="100dp" android:layout_height="100dp" android:layout_centerHorizontal="true" android:layout_gravity="center" android:background="@null" android:layout_marginTop="80dp" android:scaleType="centerCrop" android:src="@drawable/skin_about_brand" /> <ScrollView android: android:layout_width="match_parent" android:fillViewport="true" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:scrollbarThumbVertical="@android:color/transparent" android:scrollbars="vertical" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"> <LinearLayout android: android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="55dp" android:layout_marginTop="200dp" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="13dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="15dp" android:src="@drawable/ic_mobile_flag" /> <EditText android: android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@null" android:hint="@string/hint_login_username" android:inputType="textVisiblePassword" android:maxLength="11" android:singleLine="true" android:text="" android:textColor="@color/color_999999" android:textColorHint="@color/color_999999" android:textSize="14dp" /> <ImageView android: android:layout_width="40dp" android:layout_height="fill_parent" android:scaleType="centerInside" android:src="@drawable/ic_clear" android:visibility="gone" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:background="@color/color_eeeeee" /> <LinearLayout android:layout_width="match_parent" android:layout_height="55dp" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="13dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="15dp" android:src="@drawable/ic_password_flag" /> <EditText android: android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@null" android:hint="@string/hint_login_password" android:inputType="textPassword" android:maxLength="30" android:singleLine="true" android:text="" android:textColor="@color/color_999999" android:textColorHint="@color/color_999999" android:textSize="14dp" /> <ImageView android: android:layout_width="40dp" android:layout_height="fill_parent" android:scaleType="centerInside" android:src="@drawable/ic_clear" android:visibility="gone" /> <ImageView android: android:layout_width="40dp" android:layout_height="fill_parent" android:scaleType="centerInside" android:src="@drawable/pass_gone" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:background="@color/color_eeeeee" /> <Button android: android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginBottom="10dp" android:layout_marginTop="21dp" android:background="@drawable/bg_btn_login_selected" android:text="@string/login" android:textColor="@color/color_ffffff" android:textSize="18dp" /> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="wrap_content"> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginBottom="10dp" android:text="注册新用户" android:layout_weight="1" android:textColor="@color/color_b0b8b2" android:textSize="14dp" /> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginBottom="10dp" android:layout_marginLeft="21dp" android:text="@string/login_forget_pwd" android:textColor="@color/color_b0b8b2" android:textSize="14dp" /> </LinearLayout> </LinearLayout> </ScrollView> <LinearLayout android: android:layout_width="match_parent" android:orientation="horizontal" android:gravity="center" android:padding="10dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="联系客服" android:textColor="@color/color_b0b8b2" android:textSize="14dp" /> <View android:layout_width="1dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@color/color_eeeeee" android:layout_height="match_parent"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="关于我们" android:textColor="@color/color_b0b8b2" android:textSize="14dp" /> </LinearLayout></RelativeLayout>

 

图片 1CaptainAndroid.png

package com.wzh.study.login;import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.app.Activity;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.FragmentActivity;import android.support.v4.view.animation.LinearOutSlowInInterpolator;import android.text.Editable;import android.text.InputType;import android.text.TextUtils;import android.text.TextWatcher;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.view.ViewGroup;import android.view.WindowManager;import android.view.animation.LinearInterpolator;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.ScrollView;import android.widget.TextView;import android.widget.Toast;import com.wzh.study.R;/** * Created by WZH on 2017/3/25. */public class OtherLoginAct extends FragmentActivity implements View.OnClickListener { private ImageView logo; private ScrollView scrollView; private EditText et_mobile; private EditText et_password; private ImageView iv_clean_phone; private ImageView clean_password; private ImageView iv_show_pwd; private Button btn_login; private TextView forget_password; private int screenHeight = 0;//屏幕高度 private int keyHeight = 0; //软件盘弹起后所占高度 private float scale = 0.6f; //logo缩放比例 private View service,content; private int height = 0 ; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_other_login); if(isFullScreen{ AndroidBug5497Workaround.assistActivity; } initView(); initListener(); } public boolean isFullScreen(Activity activity) { return (activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)==WindowManager.LayoutParams.FLAG_FULLSCREEN; } private void initView() { logo = (ImageView) findViewById(R.id.logo); scrollView = (ScrollView) findViewById(R.id.scrollView); et_mobile =  findViewById(R.id.et_mobile); et_password =  findViewById(R.id.et_password); iv_clean_phone = (ImageView) findViewById(R.id.iv_clean_phone); clean_password = (ImageView) findViewById(R.id.clean_password); iv_show_pwd = (ImageView) findViewById(R.id.iv_show_pwd); btn_login =  findViewById(R.id.btn_login); forget_password =  findViewById(R.id.forget_password); service = findViewById(R.id.service); content = findViewById(R.id.content); screenHeight = this.getResources().getDisplayMetrics().heightPixels; //获取屏幕高度 keyHeight = screenHeight / 3;//弹起高度为屏幕高度的1/3 } private void initListener() { iv_clean_phone.setOnClickListener; clean_password.setOnClickListener; iv_show_pwd.setOnClickListener; et_mobile.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (!TextUtils.isEmpty && iv_clean_phone.getVisibility() == View.GONE) { iv_clean_phone.setVisibility(View.VISIBLE); } else if (TextUtils.isEmpty { iv_clean_phone.setVisibility(View.GONE); } } }); et_password.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (!TextUtils.isEmpty && clean_password.getVisibility() == View.GONE) { clean_password.setVisibility(View.VISIBLE); } else if (TextUtils.isEmpty { clean_password.setVisibility(View.GONE); } if (s.toString().isEmpty return; if (!s.toString().matches("[A-Za-z0-9] ")) { String temp = s.toString(); Toast.makeText(OtherLoginAct.this, R.string.please_input_limit_pwd, Toast.LENGTH_SHORT).show(); s.delete(temp.length() - 1, temp.length; et_password.setSelection(s.length; } } }); /** * 禁止键盘弹起的时候可以滚动 */ scrollView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); scrollView.addOnLayoutChangeListener(new ViewGroup.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { /* old是改变前的左上右下坐标点值,没有old的是改变后的左上右下坐标点值 现在认为只要控件将Activity向上推的高度超过了1/3屏幕高,就认为软键盘弹起*/ if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > keyHeight)) { Log.e("wenzhihao", "up------>" (oldBottom - bottom)); int dist = content.getBottom() - bottom; if (dist>0){ ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(content, "translationY", 0.0f, -dist); mAnimatorTranslateY.setDuration; mAnimatorTranslateY.setInterpolator(new LinearInterpolator; mAnimatorTranslateY.start(); zoomIn(logo, dist); } service.setVisibility(View.INVISIBLE); } else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > keyHeight)) { Log.e("wenzhihao", "down------>" (bottom - oldBottom)); if ((content.getBottom() - oldBottom)>0){ ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(content, "translationY", content.getTranslationY; mAnimatorTranslateY.setDuration; mAnimatorTranslateY.setInterpolator(new LinearInterpolator; mAnimatorTranslateY.start(); //键盘收回后,logo恢复原来大小,位置同样回到初始位置 zoomOut; } service.setVisibility(View.VISIBLE); } } }); } /** * 缩小 * @param view */ public void zoomIn(final View view, float dist) { view.setPivotY(view.getHeight; view.setPivotX(view.getWidth; AnimatorSet mAnimatorSet = new AnimatorSet(); ObjectAnimator mAnimatorScaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.0f, scale); ObjectAnimator mAnimatorScaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.0f, scale); ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(view, "translationY", 0.0f, -dist); mAnimatorSet.play(mAnimatorTranslateY).with(mAnimatorScaleX); mAnimatorSet.play(mAnimatorScaleX).with(mAnimatorScaleY); mAnimatorSet.setDuration; mAnimatorSet.start(); } /** * f放大 * @param view */ public void zoomOut(final View view) { view.setPivotY(view.getHeight; view.setPivotX(view.getWidth; AnimatorSet mAnimatorSet = new AnimatorSet(); ObjectAnimator mAnimatorScaleX = ObjectAnimator.ofFloat(view, "scaleX", scale, 1.0f); ObjectAnimator mAnimatorScaleY = ObjectAnimator.ofFloat(view, "scaleY", scale, 1.0f); ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(view, "translationY", view.getTranslationY; mAnimatorSet.play(mAnimatorTranslateY).with(mAnimatorScaleX); mAnimatorSet.play(mAnimatorScaleX).with(mAnimatorScaleY); mAnimatorSet.setDuration; mAnimatorSet.start(); } @Override public void onClick { int id = v.getId(); switch  { case R.id.iv_clean_phone: et_mobile.setText; break; case R.id.clean_password: et_password.setText; break; case R.id.iv_show_pwd: if (et_password.getInputType() != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) { et_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); iv_show_pwd.setImageResource(R.drawable.pass_visuable); } else { et_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); iv_show_pwd.setImageResource(R.drawable.pass_gone); } String pwd = et_password.getText().toString(); if (!TextUtils.isEmpty et_password.setSelection(pwd.length; break; } }}

 全局键盘显示和蒙蔽不会接触

谢谢大家阅读,如有扶持,来个钟爱或然关怀呢!

本文小编:Anderson/Jerey_Jobs

简书地址:Anderson大码渣

github地址:Jerey_Jobs

接下去就看具体动漫事件了,键盘弹起来的时候完全向上活动,LOGO收缩,键盘收起的时候完全下移,何况LOGO复苏原本大小。这里运用的都以性质动漫,只有属性动漫我们才得以兑现真正平移效果。

如此那般会显得系统状态栏。否掉!

低三下四看见那么些标题,我们都会不声不响感觉:Activity中从未得以复写的不二秘籍么?只怕说,没有何listener能够让大家使用么?抱歉,真的未有,我们鸦默雀静都以以为系统会提供,其实系统提供的是InputMethodManager,让大家决定键盘的弹出和隐身,并非键盘弹出和隐身触发事件。

小编们想让构造全体平移的离开也正是弹起时候处于最底部的view间隔顶上部分的冲天减去大家键盘的冲天。以后以为只要控件将Activity向上推的万丈超越了60%显示器高,就感觉软键盘弹起

//添加布局变化监听
root.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener() {  
                @Override  
                public void onGlobalLayout() {  
                    Rect rect = new Rect();  
                    root.getWindowVisibleDisplayFrame(rect);  
                    int rootInvisibleHeight = root.getRootView().getHeight() - rect.bottom;  
                    if (rootInvisibleHeight <= 100) { 
                        //通知c++做想做的事
                        hideKeyBoardHandler();
                    } else {
                        showKeyBoardHandler();
                    }
                }  
            }); 

总结

Android系统并从未给大家提供监听键盘弹出的措施,大家只可以和睦监听view的中度变化来直接决断键盘是或不是弹出了。同一时间愿意我们有更加好的必经之路提供

自我看互连网海人民广播广播台湾大学人利用addOnLayoutChangeListener()去监听键盘事件,可是那几个办法回调的太频仍,比方本例特效,输入框前边有文字时候显得消弭的Logo,要是用那一个主意那么也会奉行一回,大概会潜濡默化您的动漫,当然你也足以去记录第贰遍的可观让他不会走逻辑,不过本身以为亦非很可靠,即使自己那几个法子亦非很棒 ๑乛◡乛๑~。

难题大概:横板cocos2dx游戏,点击输入框弹出键盘时,分界面供给随行网络最早,无法屏蔽输入框。这种难题只现出在非全屏键盘到意况下。

本文由68399皇家赌场发布于集成经验,转载请注明出处:Android登陆页面仿拉钩动效,奇技淫巧之

关键词: An 奇技淫巧 弹出 键盘 总会

上一篇:腾讯一面,包含weak对象的初始化

下一篇:没有了

最火资讯