为什么我们使用ViewTreeObserver#addOnGlobalLayoutListener()

时间:2017-04-26 11:54:53

标签: java android android-layout android-view android-viewtreeobserver

为什么我们使用var themename = '{MY-THENE-NAME}'; var gulp = require('gulp'), // Prepare and optimize code etc autoprefixer = require('autoprefixer'), flexboxfixer = require('postcss-flexboxfixer'), browserSync = require('browser-sync').create(), image = require('gulp-image'), jshint = require('gulp-jshint'), postcss = require('gulp-postcss'), sass = require('gulp-sass'), sourcemaps = require('gulp-sourcemaps'), // Only work with new or updated files newer = require('gulp-newer'), // Name of working theme folder root = '../' + themename + '/', scss = root + 'sass/', js = root + 'js/', img = root + 'images/', languages = root + 'languages/'; // CSS via Sass and Autoprefixer gulp.task('css', function() { return gulp.src(scss + '{style.scss,rtl.scss}') .pipe(sourcemaps.init()) .pipe(sass({ outputStyle: 'expanded', indentType: 'tab', indentWidth: '1' }).on('error', sass.logError)) .pipe(postcss([ flexboxfixer, autoprefixer('last 2 versions', '> 1%') ])) .pipe(sourcemaps.write(scss + 'maps')) .pipe(gulp.dest(root)); }); // Optimize images through gulp-image gulp.task('images', function() { return gulp.src(img + 'RAW/**/*.{jpg,JPG,png}') .pipe(newer(img)) .pipe(image()) .pipe(gulp.dest(img)); }); // JavaScript gulp.task('javascript', function() { return gulp.src([js + '*.js']) .pipe(jshint()) .pipe(jshint.reporter('default')) .pipe(gulp.dest(js)); }); // Watch everything gulp.task('watch', function() { browserSync.init({ open: 'external', proxy: 'localhost/{MY-THENE-NAME}', port: 8080 }); gulp.watch([root + '**/*.css', root + '**/*.scss' ], ['css']); gulp.watch(js + '**/*.js', ['javascript']); gulp.watch(img + 'RAW/**/*.{jpg,JPG,png}', ['images']); gulp.watch(root + '**/*').on('change', browserSync.reload); }); // Default task (runs at initiation: gulp --verbose) gulp.task('default', ['watch']);,请任何人解释一下吗?

在下面的代码ViewTreeObserver中是creditsView个对象。通过这整个代码,我理解“这是基于条件隐藏一些文本”,但只有我们使用TextView的原因是什么?

ViewTreeObserver

2 个答案:

答案 0 :(得分:5)

如果您没有使用ViewTreeObserver,那么mainLayout.getRootView().getHeight()只会返回0px,因为它尚未布局(请参阅getWidth() and getHeight() of View returns 0)。

因此,您要等到视图被测量,布局,然后从中获取宽度/高度值。当视图将在屏幕上布局时,将完全触发此回调。

答案 1 :(得分:1)

不知道为什么,但是这是我搜索KOTLIN时显示给我的第一页,并且在通过Lamda之后我无法删除列表器。

这就是我在科特林所做的事情

public static byte[] sign(byte[] file) throws Exception {

    char password[] = "12345678".toCharArray();
    Provider userProvider = new sun.security.pkcs11.SunPKCS11("C:\\ForJava\\eToken.cfg");
    KeyStore ks = KeyStore.getInstance("PKCS11", userProvider);
    ks.load(null, password);   

    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    Security.addProvider(userProvider);

    //Working only with the first alias on the token
    String alias = (String)ks.aliases().nextElement();

    Signature signature = Signature.getInstance("SHA256withRSA"); 
    PrivateKey privateKey = (PrivateKey) ks.getKey(alias, password);
    signature.initSign(privateKey);
    signature.update(file);

    byte[] result = signature.sign();
    //System.out.println("result coding: \n" +new BASE64Encoder().encode(result));
    return result;
}