- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 list 中使用了 android:windowSoftInputMode="adjustResize" 来防止键盘隐藏 Activity 按钮。它可以工作,但是当键盘打开时,我的按钮会向上移动。它有点跳动,我想知道 - 我可以使用任何动画来平滑过渡吗?
<activity
android:name=".Activity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
最佳答案
方法setSoftInputMode(int)
不能被覆盖,它的实现在 Window
中类,我认为不可能自己替换当前窗口。您不能从 WindowManager
管理它也是。
您可以在 ViewGroup
上创建一个监听器并在 SoftKeyboard
时捕获修改的布局正在打开和关闭。实际上,当 SKB 出现时,容器的布局会重新绘制并更改其高度。从此事件中,您可以设法设置 Animation
在 child 的观点上,做出平滑的效果。
编辑:解决方案 by using a GlobalLayoutListener
on the rootview也可以代替(下面介绍的解决方案:)创建自定义 View 组类。
您必须创建自己的 View 组并将其作为布局中的父容器。它将实现一个将在 UI 类(Activity
、Fragment
等)中处理的接口(interface)。我找到了 this blog to detect the events on SKB for (~)all versions .根据它,这里是 View 组的类来处理高度的变化:
public class ContainerViewHandler extends RelativeLayout {
private boolean isKeyboardShown;
private onKeyboardStateChange listener;
public ContainerViewHandler(Context context) {
super(context);
}
public ContainerViewHandler(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ContainerViewHandler(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setKeyboardStateListener(onKeyboardStateChange listener) {
this.listener = listener;
}
// Callbacks
public interface onKeyboardStateChange {
void onKeyboardShow();
void onKeyboardHide();
}
@Override
public boolean dispatchKeyEventPreIme(@NonNull KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
// Keyboard is hiding
if (isKeyboardShown) {
isKeyboardShown = false;
listener.onKeyboardHide();
}
}
return super.dispatchKeyEventPreIme(event);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int proposedHeight = MeasureSpec.getSize(heightMeasureSpec);
final int actualHeight = getHeight();
if (actualHeight > proposedHeight) {
// Keyboard is showing
if (!isKeyboardShown) {
isKeyboardShown = true;
listener.onKeyboardShow();
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
现在,您必须在布局中添加此 View 组(例如 <com.package.name.ContainerViewHandler .../>
)。然后,你必须实现上面的接口(interface)setKeyboardStateListener
在 Activity 中,如下所示:
ContainerViewHandler containerView =
(ContainerViewHandler) findViewById(R.id.container_view);
containerView.setKeyboardStateListener(new ContainerHandler.onKeyboardStateChange() {
@Override
public void onKeyboardShow() {
Log.v("onKeyboardShow()", "SoftKeyboard is showing. Hello!");
}
@Override
public void onKeyboardHide() {
Log.v("onKeyboardHide()", "SoftKeyboard is hiding, Bye bye!");
}
});
因此,您可以管理不同的动画来处理和防止按钮直接“跳”到 SKB 上方。为了对此进行测试,我尝试重现反弹效果:
我的实现是这样的:
containerView.setKeyboardStateListener(new ContainerViewHandler.onKeyboardStateChange() {
@Override
public void onKeyboardShow() {
setAnimationUp();
}
@Override
public void onKeyboardHide() {
setAnimationDown();
}
});
private void setAnimationUp() {
footerButton.setVisibility(View.GONE);
float dpY = AppUtils.convertPxToDp(20, this); // custom conversion method
Animation a1 = new TranslateAnimation(0, 0, footerButton.getHeight() * 4, -(dpY));
a1.setDuration(250);
a1.setFillAfter(true);
final Animation a2 = new TranslateAnimation(0, 0, -(dpY), 0);
a2.setDuration(320);
a2.setFillAfter(true);
a1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
footerButton.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
footerButton.startAnimation(a2);
}
@Override
public void onAnimationRepeat(Animation animation) { }
});
footerButton.startAnimation(a1);
}
private void setAnimationDown() {
float dpY = AppUtils.convertPxToDp(30, this); // custom conversion method
Animation b1 = new TranslateAnimation(0, 0, -(dpY), dpY);
b1.setDuration(300);
b1.setFillAfter(true);
final Animation b2 = new TranslateAnimation(0, 0, dpY, 0);
b2.setDuration(320);
b2.setFillAfter(true);
b1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation) {
footerButton.startAnimation(b2);
}
@Override
public void onAnimationRepeat(Animation animation) { }
});
footerButton.startAnimation(b1);
}
我首先在第一个回调中设置两个动画 (a1, a2):
4xbutton's height
)下方(后面)开始,直到 20dp
在它上面,20dp
并返回 0dp
(正常位置)。第二次回调中还有另外两个(b1,b2):
30dp
的地方开始在顶部并向下转到 30dp
在父容器之外,30dp
到0dp
(初始位置)。 PS:别忘了使用 adjustResize
在 list 中制作内容(例如我测试中的编辑文本)above
页脚按钮有 alignParentBottom
为真。
关于android - AdjustResize 带动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20355053/
我想以 headless 模式(屏幕上根本没有 GUI)将 JPanel 绘制到 BufferedImage 中。 final JPanel panel = createPanel(); panel.
我是 Canvas 的新手,正在尝试创建看起来逼真的 float 粒子动画。 目前,我正在创建 400 个随机散布在 400x400 Canvas 上的粒子。 然后,在每个 requestAnimat
有没有办法在悬停时停止悬 float 画? :hover 这是一个显示动画的链接: https://codepen.io/youbiteme/pen/RprPrN 最佳答案 只需为您的 svg 悬停添
我想在谷歌地图上绘制覆盖图,其中除了特定点周围 1.5 公里半径以外的所有内容都被遮蔽了。为此,我尝试使用带有大量边框的圆圈,所以我会在边框中放置透明中心和覆盖颜色来实现这一点,但它无法渲染。
我正在尝试通过扩展类 UIView 来创建自定义 View ,该类可以在自定义 View 的中心显示一个圆圈。为了添加自定义绘图,我重写了 draw(_ rect: CGRect) 方法,如下所示。
我是一名优秀的程序员,十分优秀!