小编Ale*_*nko的帖子

RecyclerView smoothScroll位于中心位置.安卓

我正在使用水平布局管理器RecyclerView.我需要以下RecyclerView一种方式制作:当点击某个项目时 - 将smoothScrool放到该位置并将该项目放在中心RecyclerView(如果可能的话,例如20中的10项).

所以,我没有问题smoothScrollToPosition(),但如何把项目放在RecyclerView??? 的中心?

谢谢!

android android-recyclerview linearlayoutmanager

24
推荐指数
3
解决办法
2万
查看次数

谁有材料如何使用人脸检测相机2 API?

在官方消息来源没有找到信息......有很多例子说明如何使用Camera API,但是如何使用Camera2API的任何东西......在Stake和所有的一些讨论...有类似的问我,但我有一个问题没有解决...

链接到同一个 队列:Android camera2人脸识别

我以Google的相机2 API为例.

这就是我做的,但我没有发现一张脸:

我添加了活动

    private void createCameraPreviewSession() {
    try {
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        assert texture != null;

        // We configure the size of default buffer to be the size of camera preview we want.
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

        // This is the output Surface we need to start preview.
        Surface surface = new Surface(texture);

        // We set up a CaptureRequest.Builder with the output Surface.
        mPreviewRequestBuilder
                = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewRequestBuilder.addTarget(surface);

        // Here, we …
Run Code Online (Sandbox Code Playgroud)

java camera android android-camera

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

为什么我收到错误“包 org.mockito.runners 不存在”?

我已经插入了需要依赖

testCompile 'org.mockito:mockito-core:1.10.19'
Run Code Online (Sandbox Code Playgroud)

然后我把我的测试代码放到/src/test/java/目录中

然后我尝试启动这样的测试

import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class PresenterActivityAcceptNotAcceptTest {

@Test
public void emailValidator_CorrectEmailSimple_ReturnsTrue() {
    boolean dd = true;
    assertThat(dd, is(true));
} 
Run Code Online (Sandbox Code Playgroud)

它工作正常,但如果我添加任何与Mocklib相关的女巫

例如 @RunWith

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.mockito.runners.MockitoJUnitRunner;

    import static org.hamcrest.CoreMatchers.is;
    import static org.hamcrest.MatcherAssert.assertThat;

@RunWith(MockitoJUnitRunner.class)
public class PresenterActivityAcceptNotAcceptTest {


    @Test
    public void emailValidator_CorrectEmailSimple_ReturnsTrue() {
        boolean dd = true;
        assertThat(dd, is(true));
    }
Run Code Online (Sandbox Code Playgroud)

我有这样的错误

Error:Execution failed for task   ':Application:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for …
Run Code Online (Sandbox Code Playgroud)

java testing android mocking mockito

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

错误:(JetPack Compose) 类型“TypeVariable(T)”没有方法“getValue(Nothing?, KProperty<*>)”

我发现一篇文章描述了如何在LazyColumn中实现视差视图,有这样一个方法:

@Composable
    fun ImageParallaxScroll() {
        val lazyListState = rememberLazyListState()
        val list = (0..1_000).map{ "Item $it" }.toList()

        val firstItemTranslationY: LazyListState by remember {
            derivedStateOf {
                when {
                    lazyListState.layoutInfo.visibleItemsInfo.isNotEmpty() && lazyListState.firstVisibleItemIndex == 0 -> lazyListState.firstVisibleItemScrollOffset * .6f
                    else -> 0f
                }
            }
        }

            ...
    }
Run Code Online (Sandbox Code Playgroud)

问题是整个remember下划线块都带有红线,并且出现这样的错误:

Type 'TypeVariable(T)' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate
Run Code Online (Sandbox Code Playgroud)

不明白这里有什么问题?

android android-jetpack android-jetpack-compose android-compose-textfield

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

如何在 NavigationView 中设置徽章?

我使用NavigationDrawer来自 desin lib

compile 'com.android.support:design:24.0.0'
Run Code Online (Sandbox Code Playgroud)

XML

....

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main_second"
    app:menu="@menu/activity_third_drawer" />

....
Run Code Online (Sandbox Code Playgroud)

有一点我正在设置菜单

app:menu="@menu/activity_third_drawer"
Run Code Online (Sandbox Code Playgroud)

XML菜单

<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_inbox"
        android:icon="@drawable/ic_mail_outline_white"
        android:title="@string/inbox" />
    <item
        android:id="@+id/nav_gallery"
        android:icon="@drawable/ic_close_24dp"
        android:title="@string/gallery" />
    <item
        android:id="@+id/nav_slideshow"
        android:icon="@drawable/ic_close_24dp"
        android:title="@string/slideshow" />
    <item
        android:id="@+id/nav_manage"
        android:icon="@drawable/ic_close_24dp"
        android:title="@string/tools" />
</group>

<item android:title="@string/about_app">
    <menu>
        <item
            android:id="@+id/nav_about"
            android:icon="@drawable/ic_close_24dp"
            android:title="@string/about1" />
    </menu>
</item>
</menu>
Run Code Online (Sandbox Code Playgroud)

最终它看起来像这样

???????  ??? ?????????  ????????????

但我需要当消息进入收件箱时,它应该被标记为NavigationDrawer.

像这样

???????  ??? ?????????  ????????????

有很多不同的库可以帮助解决这个问题,我选择了这个

这个库可以在任何你想要的地方附加徽章,但没有一个样本锄头可以将它附加到<item>. 最接近的示例是如何附加到XML

<com.readystatesoftware.viewbadger.BadgeView
            android:id="@+id/badge"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

java xml android android-navigationview

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

如何花时间直到焦点正在拍摄图像而不是拍照?camera2API

我使用相机2 API.

我使用标准谷歌样本的相机.

问题是代码允许用户拍照,即使图像不在焦点...

private final CameraCaptureSession.CaptureCallback mCaptureCallback
        = new CameraCaptureSession.CaptureCallback() {

    @Override
    public void onCaptureProgressed(@NonNull CameraCaptureSession session,
                                    @NonNull CaptureRequest request,
                                    @NonNull CaptureResult partialResult) {
    }

    @Override
    public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                   @NonNull CaptureRequest request,
                                   @NonNull TotalCaptureResult result) {
        process(result);
    }

    private void process(CaptureResult result) {
        switch (mState) {
            case CameraHelper.STATE_PREVIEW: {
                // We have nothing to do when the camera preview is working normally.

                break;
            }
            case CameraHelper.STATE_WAITING_LOCK: {
                Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
                if (afState == null) {
                    captureStillPicture(); …
Run Code Online (Sandbox Code Playgroud)

java camera android android-camera

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

如何执行alamofire后台上传请求?

我需要将zip文件发送到服务器端。

有我的要求,我需要在后台工作

let configuration = URLSessionConfiguration.default
    configuration.timeoutIntervalForRequest = 10 // seconds
    alamoFireManager = Alamofire.SessionManager(configuration: configuration)

appDeligate.log.debug("request was sended")

    alamoFireManager.upload(deligate.data!,
                            to: deligate.url,
                            method: .post,
                            headers: headers)
        .uploadProgress(closure: {
            progress in
            print("Upload Progress: \(progress.fractionCompleted)")
        })
        .validate()
        .responseJSON {}
Run Code Online (Sandbox Code Playgroud)

现在它可以正常工作,但是我需要在后台执行此操作。根据Alamofire自述文件

https://github.com/Alamofire/Alamofire

它说

使用后台配置创建会话管理器

让配置= URLSessionConfiguration.background(withIdentifier:“ com.example.app.background”)

让sessionManager = Alamofire.SessionManager(configuration:配置)

我更改了配置以对应后台配置

现在看起来像这样

let configuration = URLSessionConfiguration.background(withIdentifier: "com.room.myApp")
configuration.timeoutIntervalForRequest = 10 // seconds
    alamoFireManager = Alamofire.SessionManager(configuration: configuration)

alamoFireManager.upload(deligate.data!,
                            to: deligate.url,
                            method: .post,
                            headers: headers)
        .uploadProgress(closure: {
            progress in
            print("Upload Progress: \(progress.fractionCompleted)")
        })
        .validate()
        .responseJSON {} …
Run Code Online (Sandbox Code Playgroud)

xcode swift alamofire

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

棉花糖的权限和解释

可以解释一下我应该如何向用户许可解释

我使用Camera2API,我实现了这样的代码片段,以恐怖的方式询问permishion

private void openCamera(int width, int height) {
    setUpCameraOutputs(width, height);
    CameraHelper.configureTransform(width, height, textureView, previewSize, getActivity());
    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

    try {
        if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) !=
                PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {

                // Show an explanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try …
Run Code Online (Sandbox Code Playgroud)

java permissions camera android android-camera

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

如何将模块包含到项目中?

有一个库

https://github.com/Yalantis/uCrop

有 2 个模块Sample-ucrop所有逻辑都位于其中

问题是 - 当我将ucrop模块复制到我的项目时也添加了这个

dependencies {
...
 implementation project(':ucrop')
....
}
Run Code Online (Sandbox Code Playgroud)

和这个

settings.gradle include ':ucrop', ':app'

据我所知,我只需要添加这一行即可将新模块包含到项目中

然后我尝试编译应用程序并收到这样的错误

解决此 BuildableArtifact 只能在任务执行期间完成。

模块“ucrop”是一个没有构建变体的 Android 项目,无法构建。请修复 build.gradle 文件中的模块配置并再次同步项目。

我的项目不想包含新模块的原因是什么?

请随意询问

谢谢

android

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

更新 gradle ver apk 大小两倍后,为什么?

我有 gradle

classpath 'com.android.tools.build:gradle:3.5.3'
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Run Code Online (Sandbox Code Playgroud)

和我的 apk 160Mb

在此处输入图片说明

然后我将其更新为

classpath 'com.android.tools.build:gradle:3.6.3'
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Run Code Online (Sandbox Code Playgroud)

我的apk大小是270Mb

在此处输入图片说明

这怎么可能?但实际上如果我构建.aab它仍然有 160Mb,所以如果我构建它的大小会增加.apk

android gradle

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