- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我看过各种关于 FAB 响应屏幕底部的 Snackbar 弹出窗口以及滚动敏感 FAB 的帖子。但是是否有 FloatingActionButton.Behavior
(或类似的)在 FAB 弹出时将其移动到键盘上方的一些实现?
现在,当我在 EditText
框中单击时,键盘会覆盖 FAB。我的目标是为 FAB 设置动画,使其始终可见,与键盘状态无关。
编辑 android:windowSoftInputMode="adjustResize"
和 ...="adjustPan"
都不会改变任何东西。好吧,adjustResize
会调整底层布局(在我的例子中是 map )的大小,但 FAB 不会移动。
最佳答案
您好,我知道它已经过时了,但是对于 future 或当前的读者/搜索者以及线程制造者,他还没有找到答案。这就是我在我的应用程序中出现这种行为的方式。
Fab 隐藏在 RecyclerView 滚动条上,当 snackbar 弹出时上升,如果 fab 未显示且 snackbar 弹出,如果您滚动,则 Fab 仍将显示在 snackbar 顶部,并在 SB 消失时向下移动,最后如果它打开 Fab,键盘将被向上推。 (抱歉,我不得不写,因为我不知道如何使用 Eclipse 模拟器提供 gif)
图片
布局
<android.support.v4.widget.DrawerLayout 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:id="@+id/layout_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GrayGood"
android:clipToPadding="false"
android:fitsSystemWindows="true" >
<android.support.design.widget.CoordinatorLayout
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:id="@+id/layout_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.design.widget.AppBarLayout
android:id="@+id/layout_appLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:background="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:clipToPadding="false" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/floating_action_button_margin"
app:layout_behavior="com.faisal.cvcd.anim.ScrollingFABAnimation"
android:src="@drawable/ic_fab"
android:tint="@color/White"
app:backgroundTint="@color/colorPrimary"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal" />
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>
如您所见,我正在使用 FabAnimation 类来覆盖它的一些默认方法。
滚动FAB动画
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
public class ScrollingFABAnimation extends
CoordinatorLayout.Behavior<FloatingActionButton> {
public ScrollingFABAnimation(Context context, AttributeSet attrs) {
super(context, attrs);
}
//For SnackBar to push up the Floating Button when it pops up
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
child.setTranslationY(translationY);
return true;
}
//For FAB to hide or show on scroll
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View directTargetChild, View target,
int nestedScrollAxes) {
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL || super.onStartNestedScroll(coordinatorLayout, child,
directTargetChild, target, nestedScrollAxes);
}
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed,
int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
child.hide();
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
child.show();
}
}
}
关于android - 使 FAB 响应软键盘显示/隐藏更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33746817/
我正试图找到一个基准来衡量用户愿意等待远程服务响应的时间。在我的例子中,响应是非常有用的,但不是对数据输入的业务关键验证。我想 HCI 领域一定已经在这方面做了一些工作。 如果您知道软实时响应的普遍接
这个问题在这里已经有了答案: What's the difference between SoftReference and WeakReference in Java? (12 个回答) 关闭6年前
社区维基 我不在乎声誉点,我只想要好的答案。请随意将此问题标记为社区 wiki。 上下文 我一直在研究《理性策划者》,并发现了以下观察结果: 逻辑编程非常有趣。 逻辑编程有时是违反直觉的 逻辑编程通常
我已阅读this article关于Java中不同类型的引用(强引用、软引用、弱引用、幻像引用),但我不太理解。 这些引用类型之间有什么区别?每种类型何时使用? 最佳答案 Java 提供了两种不同类型
我需要一个带有弱键或软键的并发 HashMap ,其中等式是 equals 而不是 ==。 对于此类键,Google Collection 默认选择 ==。 有没有办法覆盖这个选择?我应该如何进行?
我读了here使用下面的命令我们可以在 Linux 系统上模拟硬重启: echo 1 > /proc/sys/kernel/sysrq echo b > /proc/sysrq-trigger 但我想
我正在使用软件 I²C实现读取一组 Sensirion SHT21 传感器。我正在尝试找出一种让传感器回答以查看它们是否实际连接到设备的方法。我正在使用 Arduino,这意味着我所有的代码都是 C/
这个问题在这里已经有了答案: How do you determine using stat() whether a file is a symbolic link? (1 个回答) 关闭 9 年前
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我一直在使用 ICS 上的 Wifi Direct API,但有点卡住了。 在 API 中,有一个名为 createGroup 的方法可以在手机上创建一个基于遗留软件的接入点。这很棒并且有效,但我似乎
当我在 ruby 中有一个数组时,我可以在其上运行 delete_if block 。问题是它从我的数组中删除了元素。我想要相同的功能,只是不对原始数组进行更改,而是返回一个删除了对象的新数组。
在 Ubuntu Virtualbox 上运行从 Windows 移植的音频应用程序时,它报告以下内容: Devices found: OpenAL Soft OpenAL Soft 40964 in
下面是我的数据库结构的简化版本(在 MVC 2 中构建一个概念验证站点,使用 Entity Framework 4 作为我的 ORM): [Stores] StoreID (PK) StoreName
我用 ESP8266 创建了一个软 AP,我通过 android 6.0 marshmallow mobile 连接到它。连接后,如果我忽略它并打开浏览器窗口打开我的网络服务器页面或使用自定义构建的应
如何应用 Three.js online editor 中所示的 PCF (SOFT) 阴影类型以 JavaScript 代码的形式发送到你的渲染器? 最佳答案 要使用该类型的阴影,您需要使用相应类型
我知道 Wifi Direct 的工作原理是在其中一台设备中创建软 AP(软件接入点)。我也知道很多 Android 支持 Wifi Direct,但 iPhone 不支持。 我的问题是:是否可以创建
我有一个在 14.04.05 LTS 上运行的 Ubuntu 服务器。 此服务器上还安装了几个 ugins mongodb 应用程序。 MongoDB版本为3.4.2 我正在尝试增加 mongodb
我是一名优秀的程序员,十分优秀!