小编pul*_*ion的帖子

OpenCV 2.4.11和3.0.0之间有什么区别?

OpenCV的最新版本显示2015年2月2日至11日,最新版本为3.0.0,处于测试阶段.它们之间有什么区别.我应该使用OpenCV 2.4.11而不是3.0.0,因为我在3.0.0中遇到了一些错误.他们的发布如何运作?

opencv opencv3.0

28
推荐指数
3
解决办法
4万
查看次数

为什么Retrofit会宣传为"Type Safe"库?

我刚刚浏览了他们的主页,它说,

适用于Android和Java的类型安全的HTTP客户端

为什么Retrofit将自己宣传为Type Safe,而其他图书馆(许多其他受欢迎的图书馆)则没有?

在你回答之前......

有一个答案,同样的问题在这里.它说,

类型安全性是编程语言阻止或防止类型错误的程度.类型错误是由程序的常量,变量和方法(函数)的不同数据类型之间的差异引起的错误或不期望的程序行为,例如,将整数(int)视为浮点数(浮点数).这在静态类型语言(如Java和C)中很常见

因此,Retrofit可以防止此类错误

如果这确实是答案,那么许多库会阻止这些类型的错误,但它们都不会作为类型安全广告.那是营销吗?

我认为上述答案不充分,因为类型安全的定义尚未得到认真对待.

无论如何,还有另一篇文章定义了类型安全.他们给出了例子:

类型安全意味着编译器将在编译时验证类型,如果尝试将错误的类型分配给变量,则抛出错误.

一些简单的例子:

// Fails, Trying to put an integer in a string
String one = 1;
// Also fails.
int foo = "bar";
Run Code Online (Sandbox Code Playgroud)

这也适用于方法参数,因为您将显式类型传递给它们:

int AddTwoNumbers(int a, int b)
{
    return a + b;
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用以下方法调用:

int Sum = AddTwoNumbers(5, "5");
Run Code Online (Sandbox Code Playgroud)

根据上面的定义,它将是语言(Java),而不是特定于TypeSafe的库.

所以,我再次问,为什么Retrofit将自己宣传为类型安全库?

java android type-safety retrofit retrofit2

17
推荐指数
3
解决办法
859
查看次数

"this"关键字:Java中的工作机制

在学习Java一段时间之后,它第一次使用this关键字让我如此困惑.

这是我如何感到困惑.我写了以下代码:

class BasicInheritanceTest3Base{
    private int x = 0;
    public int y;

    public void a() {
        x++;
        this.x++;
        System.out.println("BasicInheritanceTest3Base.a()");
        b();
        this.b();
        System.out.println(x);
        System.out.println(y);
    }

    public void b(){
        System.out.println("BasicInheritanceTest3Base.b()");
    }
}

public class BasicInheritanceTest3 extends BasicInheritanceTest3Base {
    private int x = 3;
    public int y = 2;

    public void b() {
        System.out.println("BasicInheritanceTest3.b()");
    }

    public static void main(String[] args){
        BasicInheritanceTest3 bit2 = new BasicInheritanceTest3();
        bit2.a();
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到以下输出:

BasicInheritanceTest3Base.a()
BasicInheritanceTest3.b()
BasicInheritanceTest3.b()
2
0
Run Code Online (Sandbox Code Playgroud)

现在第一个问题是:为什么xthis.x指向x基类而不是Child类?如果 …

java this

14
推荐指数
1
解决办法
1488
查看次数

在滑动ViewPager时查看翻译

我正在阅读一个关于自定义ViewPager滑动页面动画的示例,该动画需要将页面(View)转换为一定量.这个例子来自文档.具体来说,它是关于一个被调用的实现ZoomOutPageTransformer,可以在一个ViewPager直通setPageTransformer()上设置以自定义页面的滑动方式(在其中包含缩放动画).

这是最终结果应该是这样的:

在此输入图像描述

现在,他们描述了他们将如何做到这一点:

在您的实现中transformPage(),您可以通过根据屏幕上页面的位置确定需要转换哪些页面来创建自定义幻灯片动画,该位置是从方法的position参数获得的transformPage().

position参数指示给定页面相对于屏幕中心的位置.它是一个动态属性,随着用户滚动页面而变化.当页面填满屏幕时,其position值为0.当页面刚刚从屏幕右侧绘制时,其position值为1.如果用户在第1页和第2页之间滚动,则第1页的position值为-0.5且第二页有position0.5.基于在position屏幕上的页面,你可以通过与方法,如设置页面属性创建自定义幻灯片动画setAlpha(),setTranslationX()setScaleY().

这是PageTransformer他们提供的实施:

public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
    private static final float MIN_SCALE = 0.85f;
    private static final float MIN_ALPHA = 0.5f;

    public void transformPage(View view, float position) {
        int pageWidth = view.getWidth();
        int pageHeight = …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-viewpager

14
推荐指数
1
解决办法
1552
查看次数

Parcelable中的标志有什么用?

我一直在编写Parcelables而Parcel没有关注flags字段,这是方法签名中的一个参数,它工作正常,但我遇到了一个我不能再忽略它们的实现:

public static <K extends Parcelable, V extends Parcelable> void write(Parcel dest,
                                                    Map<K, V> map, int flags) {
        if (map == null) {
            dest.writeInt(-1);
        } else {
            Set<Map.Entry<K, V>> entrySet = map.entrySet();
            dest.writeInt(entrySet.size());
            for (Map.Entry<K, V> entry : entrySet) {
                dest.writeParcelable(entry.getKey(), flags);
                dest.writeParcelable(entry.getValue(), flags);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是一个Map 向/从 Parcelable程序我已经写了,我想知道如果标志应传递,因为它是两个关键还有价值,而写他们还是应该通过0 flags.

我阅读了文档中标志的定义:

PARCELABLE_WRITE_RETURN_VALUE

在API级别1中添加

int PARCELABLE_WRITE_RETURN_VALUE
Run Code Online (Sandbox Code Playgroud)

用于的标志writeToParcel(Parcel, int):正在写入的对象是返回值,它是诸如"Parcelable someFunction()", …

flags android parcel parcelable

12
推荐指数
2
解决办法
4038
查看次数

AndroidJUnitRunner和AndroidJunit4有什么区别?

我是Android测试世界的新手,单元测试的样本提到了AndroidJunit4跑步者的使用.我偶然发现了一位名叫的跑步者AndroidJUnitRunner.现在,我看到了这两个类的文档,乍一看,似乎差异在于AndroidJunit4支持JUnit4,特别是在AndroidJUnitRunner支持JUnit3和JUnit4时,但是如果你研究类结构和可用的方法,实际上有一个巨大的区别这两位选手.

例如,AndroidJUnitRunner从以下类扩展:

在此输入图像描述

并且,AndroidJunit4从,延伸,

在此输入图像描述

那么,两位选手之间有什么区别?我最终应该使用哪名选手?

junit android android-instrumentation

10
推荐指数
1
解决办法
3096
查看次数

TextView的颜色在ConstraintLayout的真实设备上显示为白色

我一直在想我的手ConstraintLayout,至今我都喜欢它了很多,除了现在我遇到了一个奇怪的问题.相同的布局,如果我使用a设计RelativeLayout显示包含的TextViews 的颜色作为默认文本颜色(灰色)但是ConstraintLayout,它显示白色.

这既发生在真实设备上,也发生在使用Android 5.0的仿真器上,而不是在仿真器(7.0)上.有谁知道,为什么会发生这种情况?

此外,明显的解决方案似乎是手动设计TextView布局中的颜色应该是什么,但这似乎是一个黑客而不是解决方案.我有兴趣知道,为什么这首先发生,如果这个黑客是唯一的解决方案?(我不想通过强制打开颜色来修复它,TextView因为Android 7.0 上的行为是正确的)

编辑:忘了提及布局编辑器将它们都显示为黑色/灰色,这也是一个实际颜色不应该是白色的提示.


供您参考,这里有2个布局是或多或少相同(有一个Button在其中之一,TextView而不是Button在其它),其中一个出现故障.

显示为白色的布局(焦点问题):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="4dp"
    android:layout_marginBottom="4dp"
    android:layout_marginLeft="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginEnd="8dp"
    android:background="@color/lightGrey">


    <android.support.constraint.ConstraintLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:paddingBottom="10dp"
        android:elevation="2dp"
        android:id="@+id/constraintLayout">


        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@+id/guideline"
            android:layout_marginRight="8dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintHorizontal_bias="0.0"
            android:id="@+id/linearLayout"
            tools:layout_editor_absoluteY="16dp">

            <TextView
                android:text="@string/tutor_name"
                android:textStyle="bold"
                android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

9
推荐指数
1
解决办法
1180
查看次数

当我没有明确声明它们时,为什么Android会选择AppCompat组件?

我正在调试我的应用程序,并在将鼠标悬停在ImageView引用上时发现,它是一个AppCompatImageView而不是一个ImageView.a TextView(with AppCompatTextView)也是如此.

在此输入图像描述

虽然我对这种行为没有特别的问题,因为它的AppCompat毕竟是在检查开发人员的代码时,我看到了,extends Activity而不是,AppCompatActivity我几乎把它标记为"不好的做法".

另一方面,在处理矢量图像时,我使用的ImageView是一个问题,因为我没有使用过AppCompatImageView它并使用它是解决方案:

ImageView无法在设备中正确显示

这种不一致的行为让我对我应该遵循的做法感到困惑.我应该从现在开始延伸一个活动吗?

android android-appcompat

8
推荐指数
2
解决办法
362
查看次数

CoordinatorLayout:视图随自定义行为而消失

我是一个新手CoordinatorLayout,这是一个非常奇怪的现象,我在得到CoordinatorLayout.我有一个ImageView(或多个具体的子类ImageView称为CircleImageView(它安置在中心的资料相片这里))作为的一个孩子CoordinatorLayout.我把它固定CircleImageViewAppbarLayout(这是另一个孩子CoordinatorLayout).这是我的整个布局:

到现在为止还挺好.我目前能够滚动AppbarLayoutNestedScrollView移动它.但是,当我们向上滚动并决定依赖自定义时,我想到了动画配置文件向右移动CoordinatorLayour.Behavior.我最终得到了一个尝试翻译的自定义行为CircleImageView.它还没有完成,但是应该将视图大致翻译一些,除了现在,CircleImageView随着自定义行为的引入,它已经完全消失了.

可能是什么原因?

注意:我尝试用ImageView替换CircleImageView,行为保持不变.


以下是参考布局:

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="false"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            </android.support.v7.widget.Toolbar>

            <android.support.v7.widget.AppCompatImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|end"
                android:layout_marginBottom="24dp"
                android:layout_marginEnd="24dp"
                android:layout_marginRight="24dp"
                android:layout_weight="1"
                android:tint="@color/white"
                app:srcCompat="@drawable/ic_settings_24px" />

        </android.support.design.widget.CollapsingToolbarLayout>


    </android.support.design.widget.AppBarLayout>

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/profile_pic" …
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-view android-coordinatorlayout

8
推荐指数
1
解决办法
2641
查看次数

为什么我的 DialogFragment 没有显示自定义布局?

我想显示一个DialogFragment没有标题、按钮等(即,典型对话框中不包含任何内容)而只是ProgressBar一个普通背景上的微调器。对于一个粗略的想法,背景的宽度与父元素的宽度相匹配,并且微调器位于它的中心。为此,我有一个自定义布局如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <View
        android:id="@+id/search_progress_alpha_indicator"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline3"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline2"
        android:background="#00ffffff"/>

    <ProgressBar
        android:id="@+id/search_tutors_progress_bar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:visibility="gone"/>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline2"
        app:layout_constraintGuide_percent="0.20"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="126dp"
        tools:layout_editor_absoluteX="0dp" />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline3"
        app:layout_constraintGuide_percent="0.80"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="378dp"
        tools:layout_editor_absoluteX="0dp" />


</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这是应该在其上旋转View的背景ProgressBar

但是当我在 中膨胀这个布局时DialogFragment,它显示了完全不同的东西:

在此处输入图片说明

这是DialogFragment代码:

public static class SearchIndicatorDialogFragment extends DialogFragment{

        public static String FRAGMENT_TAG …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-dialogfragment

7
推荐指数
3
解决办法
5521
查看次数