小编Ema*_*nho的帖子

Dagger 2 androidx片段不兼容类型

我正在使用Dagger 2.21,而当我尝试这样做时

@Module
internal abstract class FragmentModule {
    @ContributesAndroidInjector
    internal abstract fun loginFragment() : LoginFragment
}
Run Code Online (Sandbox Code Playgroud)

@Singleton
@Component(modules = [AndroidSupportInjectionModule::class, AppModule::class, ActivityModule::class, ViewModelBuilder::class, ViewModelModule::class, RepositoriesModule::class, ApiModule::class, FragmentModule::class])
interface AppComponent : AndroidInjector<PhotocoApplication> {
    @Component.Builder
    abstract class Builder : AndroidInjector.Builder<PhotocoApplication>()
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

/app/build/generation/source/kapt/debug/com/photoco/app/injection/module/FragmentModule_LoginFragment$app_debug.java:18:错误:不兼容的类型:类LoginFragment无法转换为类扩展Fragment

我一直在搜索,发现使用2.21并将其设置为可以正常工作,但还没有运气

android.useAndroidX = true; android.enableJetifier = true

LoginFragment扩展:

dagger.android.support.DaggerFragment()

由于所有这些设置无法构建,我在这里缺少什么吗?我可以使用DaggerActivity使其与Activity一起使用,但不能与Fragments一起使用。

PhotocoApplication扩展了dagger.android.support.DaggerApplication

谢谢!

android dependency-injection kotlin dagger-2 androidx

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

CameraX PreviewView 显示全部但仅记录一个区域

我想要做的是在我的上方显示一个矩形PreviewView,并且仅记录该矩形内部的区域,即使 PreviewView 显示整个相机也是如此。

我只想将白色矩形内的内容保存到文件中,但我希望预览显示所有内容: 在此输入图像描述

活动.xml:

 <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.camera.view.PreviewView
        android:id="@+id/textureView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/crop"
        android:layout_width="350dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:background="@drawable/background_drawable"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

活动.kt

  private fun startCamera() {
    val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
    cameraProviderFuture.addListener({
        cameraProvider = cameraProviderFuture.get()

        // The display information
        val metrics = DisplayMetrics().also { textureView.display.getRealMetrics(it) }
        // The ratio for the output image and preview
        val aspectRatio = aspectRatio(metrics.widthPixels, metrics.heightPixels)
        // The display rotation
        val rotation = textureView.display.rotation

        val localCameraProvider = …
Run Code Online (Sandbox Code Playgroud)

video camera android android-camerax

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