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

  • 时间:
  • 浏览:0
  • 来源:大发5分快3APP下载_大发5分快3APP官方

}

listeners.add(listener);

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

android:text="欢迎登陆"

this.isSoftKeyboardOpened = isSoftKeyboardOpened;

import java.util.LinkedList;

drawablePadding属性照样使用,要是 设置上下左右图片的属性用自定义的吧,代码很简单,找不到贴了。

//获取status_bar_height资源的ID

android:id="@+id/logo"

notifyOnSoftKeyboardOpened(heightDiff-statusBarHeight);

private boolean isSoftKeyboardOpened;

@Override

this.isSoftKeyboardOpened = isSoftKeyboardOpened;

private int lastSoftKeyboardHeightInPx;

public KeyboardWatcher(View activityRootView, boolean isSoftKeyboardOpened) {

void onSoftKeyboardOpened(int keyboardHeightInPx);

public void addSoftKeyboardStateListener(SoftKeyboardStateListener listener) {

*/

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

}

动态效果图

android:textStyle="bold"

}

if (listener != null) {

}

}

}

}

app:drawableWidth="120dp"

android:layout_centerHorizontal="true"

void onSoftKeyboardOpened(int keyboardHeightInPx);

public void setIsSoftKeyboardOpened(boolean isSoftKeyboardOpened) {

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

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

android:layout_marginTop="200dp"

链接:

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

效果

this.activityRootView = activityRootView;

listeners.remove(listener);

private void notifyOnSoftKeyboardClosed() {

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

public class KeyboardWatcher implements ViewTreeObserver.OnGlobalLayoutListener {

notifyOnSoftKeyboardClosed();

activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(this);

import android.view.ViewTreeObserver;

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

activityRootView.getWindowVisibleDisplayFrame(r);

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

import java.util.List;

android:layout_width="wrap_content"

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

}

for (SoftKeyboardStateListener listener : listeners) {

*

}

/**

下面现在现在开始 写登陆页面的布局,也没啥难的,就我你这个 方案注意几点就行:

1.把还要往上移动的布局倒入另2个容器顶端;

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

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

4.在KeyboardWatcher.SoftKeyboardStateListener的回调接口顶端正确处理要正确处理的事,也要是 平移动画类似于的,看着玩耍吧!

isSoftKeyboardOpened = true;

public void removeSoftKeyboardStateListener(SoftKeyboardStateListener listener) {

修改后的代码如下:

return lastSoftKeyboardHeightInPx;

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

import android.view.WindowManager;

public interface SoftKeyboardStateListener {

if ((activityRootView.getContext() instanceof Activity)

void onSoftKeyboardClosed();

public KeyboardWatcher(View activityRootView) {

android:layout_height="wrap_content"

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

}

* @return last saved keyboard height in px

}

import android.view.View;

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

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

}

你这个 跟上次相比还有另2个点要是 关于显示和隐藏密码的大问题:

1.发现然后项目的显示和隐藏密码是动态设置EditText的inputType来实现的,效果不太好,怪怪的键盘抖动的赶脚。要是 用了EditText的setTransformationMethod依据来实现,想过看完就知道,棒棒的~

private final View activityRootView;

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

private int statusBarHeight = -1;

}else {

}

中心思想要是 activity根布局监听布局变化,实现ViewTreeObserver.OnGlobalLayoutListener接口,根据根布局深度1变化超欠缺度的1/4要是 认为键盘弹起来了。链接上的人是默认深度1变化超过200就认为键盘弹起,然后此处获取的键盘的深度1那么 减去状况栏的深度1,我改进了一下,当非全屏的然后获取的键盘深度1减去状况栏的深度1。

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

}

import android.app.Activity;

android:layout_gravity="center"

notifyOnSoftKeyboardOpened(heightDiff);

}

public boolean isSoftKeyboardOpened() {

android:drawablePadding="10dp"

本文作者:wenzhihao123

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

}

if (listener != null) {

for (SoftKeyboardStateListener listener : listeners) {

public int getLastSoftKeyboardHeightInPx() {

回顾

listener.onSoftKeyboardOpened(keyboardHeightInPx);

}

public boolean isFullScreen(Activity activity) {

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

private void notifyOnSoftKeyboardOpened(int keyboardHeightInPx) {

listener.onSoftKeyboardClosed();

if (resourceId > 0) {

isSoftKeyboardOpened = false;

app:drawableHeight="40dp"

import android.graphics.Rect;

return isSoftKeyboardOpened;

void onSoftKeyboardClosed();

this(activityRootView, false);

android:gravity="center_vertical"

}

android:textSize="18sp"

* Default value is zero {@code 0}.

}

public void onGlobalLayout() {

final Rect r = new Rect();

this.lastSoftKeyboardHeightInPx = keyboardHeightInPx;

}

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