小编Fir*_*axy的帖子

LayoutTransition同时消失和更改

我在这里有这个自定义的“底部操作栏”:https : //youtu.be/TPi5jtcs2wE,它在某些类型的网页(例如,文章/非文章)中出现和消失。我将最外面的设置为LinearLayoutanimateLayoutTransition并制作了另一个LayoutTransition对象,但是我希望条形图在Web视图调整其高度的同时消失。需要明确的是,条形图(relativeLayout)设置为,View.GONE并且由于条形图消失了,因此webView应该扩展为匹配父级(由于layout_weight),但是两者不能同时进行。我尝试更改LayoutTransition.setDuration().setStartDelay()

articleActivity xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:id="@+id/container_article"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="app.morningsignout.com.morningsignoff.ArticleActivity"
    tools:ignore="MergeRootFrame"
    android:background="@android:color/white"
    android:animateLayoutChanges="true">
    <app.com.morningsignout.morningsignout.CustomWebView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/webView_article"
        android:layout_gravity="center"
        android:layout_weight="9" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:layout_weight="0"
Run Code Online (Sandbox Code Playgroud)

LayoutTransition的配置:

LinearLayout container = (LinearLayout) findViewById(R.id.container_article);
LayoutTransition customTransition = new LayoutTransition();
customTransition.enableTransitionType(LayoutTransition.CHANGING);
customTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING);
customTransition.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
customTransition.setAnimator(LayoutTransition.APPEARING, showArticleBar);
customTransition.setAnimator(LayoutTransition.DISAPPEARING, hideArticleBar);
customTransition.setStartDelay(LayoutTransition.APPEARING, 0);
customTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
customTransition.setStartDelay(LayoutTransition.CHANGING, 0);
customTransition.setDuration(LayoutTransition.APPEARING, showArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.DISAPPEARING, hideArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.APPEARING, showArticleBar.getDuration());

container.setLayoutTransition(customTransition);
Run Code Online (Sandbox Code Playgroud)

hide_action_bar.xml:

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:propertyName="translationY"
    android:duration="300" …
Run Code Online (Sandbox Code Playgroud)

android objectanimator layouttransition

5
推荐指数
1
解决办法
1573
查看次数

C++ 中带有线程的时钟函数

这里有一个非常有趣的注释:http ://en.cppreference.com/w/cpp/chrono/c/clock

“只有对 std::clock 的不同调用返回的两个值之间的差异才有意义,因为 std::clock 时代的开始不必与程序的开始一致。std::clock 时间可能提前得更快或比挂钟慢,取决于操作系统给予程序的执行资源。例如,如果CPU被其他进程共享,则std::clock时间可能比挂钟慢。另一方面,如果当前进程是多线程的,并且有多个执行核心可用,std::clock 时间可能比挂钟提前。

为什么多线程会加快时钟速度?我正在检查使用线程与不使用线程的 C++ 程序的性能,我注意到线程的时间相似(不是更好),但感觉更快(比如在 3 秒的运行时中运行 8 秒)。

c++ performance multithreading clock

5
推荐指数
1
解决办法
3105
查看次数

为什么在头文件中定义函数会产生多个定义错误,而不是类?

这个问题建立在这两个 stackoverflow 帖子的基础上:

问题是:为什么类/结构/枚举不会出现多重定义错误?为什么它只适用于函数或变量?

我写了一些示例代码来试图解决我的困惑。有 4 个文件:namespace.h、test.h、test.cpp 和 main.cpp。第一个文件包含在 test.cpp 和 main.cpp 中,如果取消注释正确的行,则会导致多重定义错误。

// namespace.h
#ifndef NAMESPACE_H
#define NAMESPACE_H

namespace NamespaceTest {
    // 1. Function in namespace: must be declaration, not defintion
    int test(); // GOOD

    // int test() { // BAD
    //    return 5;
    //}

    // 2. Classes can live in header file with full implementation
    // But if the function is defined outside of the struct, it causes compiler error
    struct TestStruct {
        int x; …
Run Code Online (Sandbox Code Playgroud)

c++ namespaces g++

5
推荐指数
1
解决办法
1445
查看次数