小编abb*_*767的帖子

ConstraintLayout出错:找不到与给定名称匹配的资源

我学习了如何使用ConstraintLayout.并有问题.

我的activity_test.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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:padding="@dimen/default_padding">

    <RelativeLayout
        android:id="@+id/reserved_layout_search"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="@id/btnScanQRCode"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/btnScanQRCode"
        app:layout_constraintTop_toTopOf="parent">

        <EditText
            android:id="@+id/etSearchWorker"
            style="@style/EditTextSearch"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

        <Button
            android:id="@+id/btnClearSearch"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@drawable/ic_clear"/>

    </RelativeLayout>

    <Button
        android:id="@+id/btnScanQRCode"
        android:layout_width="@dimen/search_qr_button_size"
        android:layout_height="@dimen/search_qr_button_size"
        android:background="@drawable/button_qr_background"
        android:text="@string/button_qr_text"
        android:textColor="@color/white"
        app:layout_constraintLeft_toRightOf="@id/reserved_layout_search"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/tvPlanningCountInfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="ddsadsas"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/tvReservedContInfo"
        app:layout_constraintTop_toBottomOf="@id/btnScanQRCode"
        />

    <TextView
        android:id="@+id/tvReservedContInfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="dsdsadasdasad :44"
        app:layout_constraintLeft_toRightOf="@id/tvPlanningCountInfo"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/tvPlanningCountInfo"
        />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvReserved"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="@dimen/default_padding"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tvPlanningCountInfo"
        app:layout_constraintBottom_toBottomOf="parent"
        />

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

当我构建/重建/清理项目时我处理错误:

/Users/ME/Documents/Projects/testApp/app/src/main/res/layout/activity_test.xml
Error:(14, …
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout

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

如何在匿名课堂中引用自己?

我有下一个代码kotlin:

handler.postDelayed(object : Runnable {
            override fun run() {
                Timber.i("run post msg")
                handler.postDelayed(this, AppPrefs.SEARCH_DELAY)
            }
        },AppPrefs.SOCKET_INTERVAL)
Run Code Online (Sandbox Code Playgroud)

你如何看待它是创建延迟任务的简单标准方法(with Runnable class).this对anonimus Object的值引用实现Runnable并编译并正常工作

但是当我为此制作lamdba时:

handler.postDelayed({
            Timber.i("run post msg")
            handler.postDelayed(this, AppPrefs.SOCKET_INTERVAL)
        },AppPrefs.SOCKET_INTERVAL)
Run Code Online (Sandbox Code Playgroud)

this引用外层类.

如何从内部的anonimus类引用自己?

kotlin

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

如何在Android上测试打盹模式?

有一个旧的Android应用程序,它工作后台2服务(服务).

更新应用程序时可能会发送数据和记录,而工作不是新的DozeMode.在修改当前代码之前,我决定检查一切现在如何工作.要运行应用程序,在日志中我看到两个服务都在运行(读取设备位置的服务的基本含义,第二个服务将数据发送到服务器).使用命令关闭屏幕

adb shell dumpsys deviceidle step
Run Code Online (Sandbox Code Playgroud)

将系统转换为DozeMode:

Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: ACTIVE
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: IDLE_PENDING
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: SENSING
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: LOCATING
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: IDLE
Run Code Online (Sandbox Code Playgroud)

如果我理解正确的一切 - IDLE只是相同的模式,根据文档,所有服务,jobsheduler,报警管理器和其他背景组件应该被关闭.但这不会发生.根据日志判断,应用程序按预期工作,DozeMode要么我做错了.

告诉我,也许有任何最佳实践用于测试DozeMode和(后期)将服务重写为更现代的,如果在后台有任何行动(即当你关闭应用程序时).

Android 6,BlackView BV6000S,应用程序在允许非最佳电池寿命的列表中丢失(白名单)

UPD:Nikita:app NG$ adb shell dumpsys deviceidle force-idle 现在被迫进入空闲模式app工作

android adb android-service android-doze

6
推荐指数
1
解决办法
5937
查看次数

如何处理 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 的用户回答?

目前我向用户询问有关节省电池电量的应用程序功能:

public void startSessionClick(View view) {

        String token = MyApp.getInstance().getPrefToken();
        if (!TextUtils.isEmpty(token)) {
            throw new RuntimeException("Token is not empty");
        }

        //todo hot-fix
        if (checkBatteryOptimization()) {
            Intent intent = new Intent(this, AuthEnterPhoneActivity.class);
            startActivityForResult(intent, REQUEST_CODE_ENTER_PHONE);
        } else {
            String packageName = getApplicationContext().getPackageName();
            Intent intent = new Intent();
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            getApplicationContext().startActivity(intent);
            //handleAnswer();
            startSessionClick(null);
        }
    }
Run Code Online (Sandbox Code Playgroud)

如何追踪同意或拒绝对话?

在协议的那一刻,我只是打开下一个活动(在此之前检查库存设置),如果用户拒绝,则再次显示此对话框。

我需要的跟踪是在无法显示带有解释的对话框的情况下。

android android-intent android-doze

6
推荐指数
1
解决办法
445
查看次数

如何在android studio 3中制作转储堆?

我将设备连接到我的计算机,打开一个新的Android Profiler选项卡并运行我的应用程序.

我看到3个图形.点击记录内存分配: 红色圆圈 2-3秒后,在设备中进行大量点击(进行测试),我点击停止按钮:灰色方块

并且......分析器关闭,转储未显示,我的应用程序已关闭(错误或任何日志除外).

我做错了什么?

PS:在Android Device Monitor中行为是一样的

android memory-leaks android-studio-3.0

5
推荐指数
0
解决办法
421
查看次数

Room 2 dao 交易是真的吗?

Room有 2 个表/Dao - PoolDao 和 AccountDao 具有一对多的关系(一个池多个帐户)。我需要先创建和保存池,然后再创建和保存(一个或多个)帐户。

如何在房间内创建两个 Dao 操作的交易?在文档中,我发现只有一个 dao 的交易 - https://developer.android.com/reference/android/arch/persistence/room/Transaction

android android-room

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

如何用javapoet生成Class参数?

我需要为枚举类生成下一个 java.class 参数:

    public enum ServiceType {

        //....
        private final Class<?> mClass; //<<how?

        ServiceType(final Class<?> clazz) {
            this.mClass = clazz;
        }

        public Class<?> getCurrentClass() {
            return mClass;
        }
        //...
    }
Run Code Online (Sandbox Code Playgroud)

我没有找到 - 如何制作这个领域。

我生成这个类的代码:

        File path = new File(Path.ROOT + ENUM_PATH);

        TypeSpec.Builder servicesEnumBuilder = TypeSpec.enumBuilder(ENUM_CLASS_NAME)
                .addModifiers(Modifier.PUBLIC);

        for (Map.Entry<String, String> entry: foundedServices.entrySet()) {
            servicesEnumBuilder.addEnumConstant(
                    entry.getKey().toUpperCase() + ENUM_SUFFIX,
                    TypeSpec.anonymousClassBuilder("$T", ClassName.get(entry.getValue() , entry.getKey())).build());
        }

        servicesEnumBuilder.addField(); //<< how add this field: private final Class<?> mClass;
Run Code Online (Sandbox Code Playgroud)

java javapoet

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