Android登陆页面仿拉钩平滑动画过度动效

  • 时间:
  • 浏览:2
  • 来源:uu快3官网app_uu快3豹子赚钱

listeners.add(listener);

notifyOnSoftKeyboardOpened(heightDiff-statusBarHeight);

android:textSize="18sp"

}

private int lastSoftKeyboardHeightInPx;

}

}

android:drawablePadding="10dp"

void onSoftKeyboardOpened(int keyboardHeightInPx);

return isSoftKeyboardOpened;

android:layout_width="wrap_content"

}

android:layout_height="wrap_content"

public boolean isSoftKeyboardOpened() {

app:leftDrawable="@drawable/google" />

for (SoftKeyboardStateListener listener : listeners) {

app:drawableHeight="40dp"

}

import android.graphics.Rect;

下面开使写登陆页面的布局,也没啥难的,就我一点方案注意几点就行:

1.把可不可以 往上移动的布局放入有一一四个容器中间;

2.容器的厚度计算好,给出定值;

3.登录页面设置键盘模式为:android:windowSoftInputMode="adjustResize"

4.在KeyboardWatcher.SoftKeyboardStateListener的回调接口中间处里要处里的事,也怎么让平移动画同类的,看着玩耍吧!

} else if (isSoftKeyboardOpened &amp;&amp; heightDiff < activityRootView.getRootView().getHeight()/4) {

* Default value is zero {@code 0}.

listener.onSoftKeyboardClosed();

本文来自云栖社区合作伙伴“安卓巴士Android开发者门户”,了解相关信息可不可以 关注“安卓巴士Android开发者门户”。

中心思想怎么让activity根布局监听布局变化,实现ViewTreeObserver.OnGlobalLayoutListener接口,根据根布局厚度变化超过高 度的1/4怎么让认为键盘弹起来了。链接上的人是默认厚度变化超过30就认为键盘弹起,怎么让此处获取的键盘的厚度这样减去状况栏的厚度,我改进了一下,当非全屏的以前获取的键盘厚度减去状况栏的厚度。

*/

修改后的代码如下:

if ((activityRootView.getContext() instanceof Activity)

private int statusBarHeight = -1;

this.isSoftKeyboardOpened = isSoftKeyboardOpened;

listeners.remove(listener);

isSoftKeyboardOpened = false;

statusBarHeight = activityRootView.getContext().getResources().getDimensionPixelSize(resourceId);

}

public int getLastSoftKeyboardHeightInPx() {

return lastSoftKeyboardHeightInPx;

this.activityRootView = activityRootView;

android:gravity="center_vertical"

import android.view.WindowManager;

public KeyboardWatcher(View activityRootView) {

public void setIsSoftKeyboardOpened(boolean isSoftKeyboardOpened) {

public class KeyboardWatcher implements ViewTreeObserver.OnGlobalLayoutListener {

for (SoftKeyboardStateListener listener : listeners) {

this(activityRootView, false);

if (listener != null) {

void onSoftKeyboardClosed();

app:drawableWidth="120dp"

回顾

本文作者:wenzhihao123

return (activity.getWindow().getAttributes().flags &amp;

int resourceId = activityRootView.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");

public void addSoftKeyboardStateListener(SoftKeyboardStateListener listener) {

listener.onSoftKeyboardOpened(keyboardHeightInPx);

import android.app.Activity;

private boolean isSoftKeyboardOpened;

}

}

}

void onSoftKeyboardOpened(int keyboardHeightInPx);

}

效果

this.isSoftKeyboardOpened = isSoftKeyboardOpened;

android:layout_centerHorizontal="true"

//根据资源ID获取响应的尺寸值

void onSoftKeyboardClosed();

android:layout_gravity="center"

}

private final List<SoftKeyboardStateListener> listeners = new LinkedList<SoftKeyboardStateListener>();

import android.view.View;

原文发布时间为:2018-10-31

}

if (listener != null) {

public boolean isFullScreen(Activity activity) {

android:id="@+id/logo"

isSoftKeyboardOpened = true;

android:text="欢迎登陆"

2.封装了TextView的上下左右Drawable,可不可以 实现动态在布局文件设置大小及资源,省的在Act or Frg去设置了:

WindowManager.LayoutParams.FLAG_FULLSCREEN)==WindowManager.LayoutParams.FLAG_FULLSCREEN;

}

android:textStyle="bold"

<com.wzh.study.login.suggest.DrawableTextView

if (!isSoftKeyboardOpened &amp;&amp; heightDiff > activityRootView.getRootView().getHeight()/4) {

}

if (resourceId > 0) {

//获取status_bar_height资源的ID

activityRootView.getWindowVisibleDisplayFrame(r);

public KeyboardWatcher(View activityRootView, boolean isSoftKeyboardOpened) {

动态效果图

}

public void removeSoftKeyboardStateListener(SoftKeyboardStateListener listener) {

final Rect r = new Rect();

@Override

*

//r will be populated with the coordinates of your view that area still visible.

import java.util.LinkedList;

}

drawablePadding属性照样使用,怎么让设置上下左右图片的属性用自定义的吧,代码很简单,沒有贴了。

android:layout_marginTop="30dp"

activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(this);

}

}

一点跟上次相比还有一一四个点怎么让关于显示和隐藏密码的问题:

1.发现以前项目的显示和隐藏密码是动态设置EditText的inputType来实现的,效果不太好,不怎么键盘抖动的赶脚。一点一点用了EditText的setTransformationMethod方式来实现,想过看过就知道,棒棒的~

private void notifyOnSoftKeyboardClosed() {

* @return last saved keyboard height in px

}

}

import java.util.List;

this.lastSoftKeyboardHeightInPx = keyboardHeightInPx;

&amp;&amp; !isFullScreen((Activity) activityRootView.getContext())){

以前记录过一篇实现仿拉钩特效的文章《Android登陆页面仿拉钩动效,你总会可不可以 它!》(可点击查看),那个实现的还是趋于稳定一点问题的,根据一点老外见面 的反馈的状况,一点一点今天有时间又看过一下一点效果。今天带来相对完美一点的demo,关于键盘事件参考了Stack Overflow上以为大神的做法,在此基础上稍微修改了一点bug。

notifyOnSoftKeyboardOpened(heightDiff);

}else {

private final View activityRootView;

链接:

https://stackoverflow.com/questions/32497840/how-to-hide-ad-banner-when-opened-keyboard-on-android

import android.view.ViewTreeObserver;

public void onGlobalLayout() {

private void notifyOnSoftKeyboardOpened(int keyboardHeightInPx) {

notifyOnSoftKeyboardClosed();

/**

final int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);

public interface SoftKeyboardStateListener {