小编pro*_*m85的帖子

android - xml - 多次包含相同的布局不起作用

我试图将以下布局包括两次:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<com.viewpagerindicator.TabPageIndicator
    android:id="@+id/indicator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)

如下

<include
    android:id="@+id/include1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    layout="@layout/view_pager" />

<include
    android:id="@+id/include2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    layout="@layout/view_pager" />
Run Code Online (Sandbox Code Playgroud)

其实,如果我那样做第二种观点寻呼机不工作......第二种观点寻呼机始终保持空...如果我复制我的view_pager布局和改变的ID在此布局(寻呼机pager2和指标来INDICATOR2)一切正常.有没有更好的方法呢?复制布局以实现这似乎使包含无用的多个包括相同的布局....

我认为我正确地得到了参考文献,但是如果我包含相同的布局它就行不通...

pager1= (ViewPager)(findViewById(R.id.include1).findViewById(R.id.pager));
pager2= (ViewPager)(findViewById(R.id.include2).findViewById(R.id.pager));
Run Code Online (Sandbox Code Playgroud)

如果我复制布局,一切都很完美......

编辑:

我认为它与FragmentManager有关,因为视图寻呼机具有相同的ID ...但我不知道如何正确解决...

xml layout android include

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

RXJava - 一个接一个地运行多个observable(比如concat,但每个observable都有onCompleted)

有没有办法实现以下目标:

我有3个类型的观察者Observable<MyData>.我想要的是:

  • 运行第一个可观察的
  • 观察onCompleted第一个观察者
  • 运行第二个observable
  • 观察onCompleted第二个可观测量
  • 运行第三个observable
  • 观察onCompleted第三个可观测量

这可以用,concat但我只能观察到最后一次onCompleted.

难看的解决方案

我知道,我可以实现这一目标,如果我onCompleted从前一个事件中开始下一个可以理解的话.

即使使用任意数量的可观察量,还有其他方法可以实现这一点吗?我想避免从onCompleted事件中将这一切联系在一起,因为这看起来非常丑陋,链接越深,它就越不清楚......

编辑 - UseCase

  • 首先,我想发出代表我的应用程序上次启动时加载的数据的数据(我将数据序列化为光盘)=>原因是,我想要一个非常快速的应用程序启动
  • 然后我想要第二次数据加载,以在空状态下加载最新数据
  • 然后我想要第三次加载数据来加载最新数据的缺失深层数据

我想不断更新UI,我想知道,每个级别的数据加载完成

android reactive-programming rx-java

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

SlidingPaneLayout - 如何始终显示滑出视图的一小部分(如在环聊中)

我正在使用一个简单的SlidingPaneLayout,我想要的是:

我想,一点点滑出视图总是可见的,这样用户总能看到,有一些东西可以拉出来......就像在环聊中一样.

这有可能吗?

android slidingpanelayout

7
推荐指数
1
解决办法
2498
查看次数

Proguard - 也使用模块中的proguard文件

我的项目build.gradle如下所示:

android { 
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "..."
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':androKnife')
}
Run Code Online (Sandbox Code Playgroud)

我的androKnife模块确实拥有自己的proguard文件.如何让我的主项目也使用此文件?

如果我编译项目,有没有办法自动合并所有模块的所有proguard文件?模块是否有另一种方法可以指定它的proguard规则,项目可以继承它吗?

android proguard gradle android-studio android-proguard

7
推荐指数
1
解决办法
4194
查看次数

NullPointerException - Drawable.setBounds - 可能是由于片段转换

我收到了以下错误,我不知道为什么(这个错误非常罕见且对我来说不可重复):

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setBounds(int, int, int, int)' on a null object reference
at android.widget.ImageView.animateTransform(ImageView.java:1126)
at android.transition.ChangeImageTransform$2.set(ChangeImageTransform.java:64)
at android.transition.ChangeImageTransform$2.set(ChangeImageTransform.java:61)
at android.animation.PropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:938)
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:211)
at android.app.ActivityThread.main(ActivityThread.java:5321)
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:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Run Code Online (Sandbox Code Playgroud)

我认为它与android FragmentActivity过渡有关,但我不确定......以上是完整的堆栈跟踪.

也许有趣,我正在使用支持库

有没有人知道这是从哪里来的,以及如何防止它?

编辑

如评论中所述:

  • 我不知道这个异常来自哪个代码块
  • 我自己没有动画
  • 我假设,这个问题来自片段之间的交易(我在我的应用中使用的唯一动画)

EDIT2

我不知道我必须确保ImageView确实有内容.这可能导致上述错误,ImageView即还没有图像.

java android transformation nullpointerexception android-fragments

7
推荐指数
1
解决办法
3747
查看次数

即时运行不起作用

前提

由于我使用android studio 2.0(发行版),因此在编译我的应用程序时会得到许多内部类错误(这些似乎不相关,因为应用程序仍能正常工作).当我禁用即时运行时,我的应用程序工作正常,如果我启用它,应用程序崩溃

意见

编译时的错误如下:

Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.samsung.android.sdk.pass.e) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it …
Run Code Online (Sandbox Code Playgroud)

android instant-run

7
推荐指数
1
解决办法
1924
查看次数

PopupWindow背景有时变得透明和紫色

这是我创建一个PopupWindow:

private static PopupWindow createPopup(FragmentActivity activity, View view)
{
    PopupWindow popup = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
    popup.setOutsideTouchable(true);
    popup.setFocusable(true);
    popup.setBackgroundDrawable(new ColorDrawable(Tools.getThemeReference(activity, R.attr.main_background_color)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        popup.setElevation(Tools.convertDpToPixel(8, activity));
    PopupWindowCompat.setOverlapAnchor(popup, true);

    return popup;
}
Run Code Online (Sandbox Code Playgroud)

main_background_color是纯色,白色或黑色,取决于主题.有时发生以下情况

在此输入图像描述

我怎么能避免这个?它只发生在带有android 6 SOMETIMES的模拟器中......例如,通常情况下,PopupWindow背景按预期运行...

编辑

另外,这是我的getThemeReference方法:

public static int getThemeReference(Context context, int attribute)
{
    TypedValue typeValue = new TypedValue();
    context.getTheme().resolveAttribute(attribute, typeValue, false);
    if (typeValue.type == TypedValue.TYPE_REFERENCE)
    {
        int ref = typeValue.data;
        return ref;
    }
    else
    {
        return -1;
    }
} …
Run Code Online (Sandbox Code Playgroud)

android popupwindow android-popupwindow

7
推荐指数
1
解决办法
584
查看次数

通知 - 点击引发错误的PendingIntent

我有以下内容意图的通知:

clickIntent = PendingIntent.getService(
                    getApplicationContext(),
                    Constants.REQUEST_CODE_NOTIFICATION_OTHER,
                    new Intent(getApplicationContext(), MainService.class)
                            .putExtra(Constants.EVENT, Constants.EVENT_TOGGLE_BLACK),
                    PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)

以及具有以下行动意图的一项行动:

PendingIntent closeIntent = PendingIntent.getService(
        getApplicationContext(),
        Constants.REQUEST_CODE_NOTIFICATION_OTHER,
        new Intent(getApplicationContext(), MainService.class)
                .putExtra(Constants.EVENT, Constants.EVENT_DISABLE_SERVICE),
        PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)

单击通知时,将触发关闭意图.为什么?

以下是我创建通知的方法:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(text))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(details)))
            .setSmallIcon(R.drawable.ic_not)
            .setContentIntent(clickIntent)
            .setOngoing(true);

    boolean showCloseButton = MainApp.getPrefs().enableCloseServiceButtonInNotification();
    if (showCloseButton)
        builder.addAction(R.drawable.ic_close_black_24dp, getString(R.string.stop_service), closeIntent);
Run Code Online (Sandbox Code Playgroud)

notifications android android-intent android-notifications

7
推荐指数
1
解决办法
630
查看次数

在WindowManager中查看的onConfigurationChanged不可靠

我加入ViewWindowManager并覆盖它onConfigurationChanged就像以下功能:

查看代码

// onConfigurationChanged should be called after config change has finished
override fun onConfigurationChanged(newConfig: Configuration) {
    super.onConfigurationChanged(newConfig)
    // also tried executing following in the `GlobalLayoutListener` without any difference
    onConfigOrSystemUIChanged(newConfig)
}

fun onConfigOrSystemUIChanged(newConfig: Configuration?) {
    val screen = getScreenSize(this)

    // screen should hold current screen size
    // but this sometimes contains the wrong size, the one from before the config change

    L.d("[%s] Config changed (%s)", logBaseInfo, screen)
}
Run Code Online (Sandbox Code Playgroud)

服务代码

override fun onConfigurationChanged(newConfig: Configuration) { …
Run Code Online (Sandbox Code Playgroud)

android window-managers android-windowmanager

7
推荐指数
1
解决办法
133
查看次数

Setting TextView text to static text crashes (rarely) with ArrayIndexOutOfBoundsException

By simply setting a TextViews text to a string defined in code (that never can be null) I sometimes get an ArrayIndexOutOfBoundsException, this only happens in my live app, I never had this issue on any test device yet... And it seems to happen sometimes only, the user tells me it happens once and the next time everything works again. Any ideas what could be the cause here? For me, it looks like this crash should never ever …

android indexoutofboundsexception kotlin

7
推荐指数
1
解决办法
261
查看次数