我正在尝试将 AppBarLayout 的高度设置为 0(然后返回到默认值)。它在 API 21(>= 22 等工作正常)上有时(不总是)和仅崩溃。
我正在使用 StateListAnimator,如下面的链接所述(因为这是自 support-lib 24.0.0 以来设置高度的“官方”方式):
https://stackoverflow.com/a/37992366/2170109
我的实际方法是这样的:
public void setAppBarElevation(final boolean visible) {
if (appBar != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
appBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(this, (visible) ? R.animator.appbar_elevated : R.animator.appbar_not_elevated));
}
}
连同两个 XML 文件(另一个是设置 android:valueTo="0"):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<objectAnimator android:propertyName="elevation"
android:valueTo="@dimen/default_appbar_elevation"
android:valueType="floatType"/>
</item>
</selector>
我已经测试了一些具有不同 Android 版本(API 19、21、23、24、25)的设备,它只在 21 时崩溃。
日志显示设置高度时出现一些 JNI 错误(我认为来自 StateListAnimator):
--------- beginning of system
JNI DETECTED ERROR IN APPLICATION: cant call void android.view.View.setElevation(float) on null object
in call to CallVoidMethodV
from void android.animation.PropertyValuesHolder.nCallFloatMethod(java.lang.Object, long, float)
"main" prio=5 tid=1 Runnable
| group="main" sCount=0 dsCount=0 obj=0x72fc2000 self=0xf421c500
| sysTid=20172 nice=0 cgrp=apps sched=0/0 handle=0xf77de160
| state=R schedstat=( 3803514732 320072004 1563 ) utm=340 stm=40 core=0 HZ=100
| stack=0xff6fb000-0xff6fd000 stackSize=8MB
| held mutexes= "mutator lock"(shared held)
native: #00 pc 00005b13 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+83)
native: #01 pc 00002e92 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+34)
native: #02 pc 003c8f68 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+136)
native: #03 pc 00391f8d /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+285)
native: #04 pc 001006b0 /system/lib/libart.so (art::JniAbort(char const*, char const*)+1024)
native: #05 pc 0010125f /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+111)
native: #06 pc 001016b2 /system/lib/libart.so (art::ScopedCheck::CheckVirtualMethod(_jobject*, _jmethodID*)+514)
native: #07 pc 00112340 /system/lib/libart.so (art::CheckJNI::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, char*)+144)
native: #08 pc 000776ca /system/lib/libandroid_runtime.so (_JNIEnv::CallVoidMethod(_jobject*, _jmethodID*, ...)+42)
native: #09 pc 00123ecb /system/lib/libandroid_runtime.so (???)
native: #10 pc 00089596 /data/dalvik-cache/x86/system@framework@boot.oat (Java_android_animation_PropertyValuesHolder_nCallFloatMethod__Ljava_lang_Object_2JF+174)
at android.animation.PropertyValuesHolder.nCallFloatMethod(Native method)
at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1296)
at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:952)
at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1207)
at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1248)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:659)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:682)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5219)
at java.lang.reflect.Method.invoke!(Native method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
有什么方法可以使用当前的支持库隐藏 AppBar 的影子(并重新启用它)(我现在使用的是 25.0.0,但它会在 24.0 时崩溃。 x.x,也是)?
最佳答案
你可以试试android:stateListAnimator="@null"来隐藏
关于为 AppBarLayout 设置 elevation/StateListAnimator 时 Android JNI 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40404009/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r
我正在尝试为我的iOS应用程序设置cocoapods但是当我执行命令时:sudogemupdate--system我收到错误消息:当前已安装最新版本。中止。当我进入cocoapods的下一步时:sudogeminstallcocoapods我在MacOS10.8.5上遇到错误:ERROR:Errorinstallingcocoapods:cocoapods-trunkrequiresRubyversion>=2.0.0.我在MacOS10.9.4上尝试了同样的操作,但出现错误:ERROR:Couldnotfindavalidgem'cocoapods'(>=0),hereiswhy:U
我正在构建一个应用程序,想知道是否将未使用的对象设置为nil是生产级编码中的常见做法。我知道这只是垃圾收集器的提示,并不总是处理对象。 最佳答案 根据这个thread如果您使用完一个成员对象,将其设置为nil将引发被引用对象被垃圾回收。如果它是局部变量,方法exit将做同样的事情。也就是说,如果您要求将成员显式设置为nil,我会质疑您的设计。 关于ruby-将对象设置为nil是否很常见?,我们在StackOverflow上找到一个类似的问题: https://