小编cpg*_*en2的帖子

ShapeableImageView 有黑色覆盖

我正在使用新的 ShapeableImageView 制作圆形图像,但叠加层显示为黑色。我怎样才能使它透明?这是它的样子:

在此处输入图片说明

这是代码:

<com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/app_icon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:shapeAppearanceOverlay="@style/CircleImageView"
        app:srcCompat="@mipmap/ic_launcher_round" />
Run Code Online (Sandbox Code Playgroud)
<style name="CircleImageView">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">50%</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

android android-xml kotlin

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

如何在 LazyColumn Jetpack Compose 中的项目之间添加分隔线?

我有一个如下所示的 LazyColumn:

LazyColumn (
    verticalArrangement = Arrangement.spacedBy(12.dp)
) {
    items(bookList) { book ->
        InProgressBookItem(book = book)
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在列表中的每个项目之间添加一行,类似于在旧的 RecyclerView 上使用项目装饰?

android android-jetpack-compose android-jetpack-compose-list

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

java.lang.IllegalStateException:API 响应后片段未附加到上下文

在我的应用程序中,我有一个用于显示数据的片段,以及一个用于更改应用程序中某些设置的设置活动。当我通过导航抽屉进入设置活动,然后返回主屏幕(不更改设置)时,应用程序崩溃并出现以下异常:

java.lang.IllegalStateException: Fragment NowWeatherFragment{b7914f8 (0e67ee0d-8776-45b5-9fd7-ee69841c31d1)} not attached to a context

它似乎是在 API 调用的响应之后发生的,并且从关于 SO 的另一个答案中可以很好地解释原因,但是我尝试过的任何方法都无法解决这个问题。

我已经看到了其他几个关于此的问题,但是我无法将这些答案应用于我的情况。我尝试检查 isAttached() 并且没有帮助,并且对片段进行空检查,但它仍然得到相同的异常

不是发布所有类,其中一些很长,这里是 github repo。通过 Android Studio https://github.com/jollygreenegiant/SimpleWeather在设备上运行应该是相当轻量和容易的

我希望该应用程序会像启动时一样返回主屏幕并显示天气数据。

这是完整的堆栈跟踪:

java.lang.IllegalStateException: Fragment NowWeatherFragment{b7914f8 (0e67ee0d-8776-45b5-9fd7-ee69841c31d1)} not attached to a context.
        at androidx.fragment.app.Fragment.requireContext(Fragment.java:765)
        at androidx.fragment.app.Fragment.getResources(Fragment.java:829)
        at com.jggdevelopment.simpleweather.fragments.NowWeatherFragment.setupViews(NowWeatherFragment.java:82)
        at com.jggdevelopment.simpleweather.fragments.NowWeatherFragment$3.onSharedPreferenceChanged(NowWeatherFragment.java:152)
        at android.app.SharedPreferencesImpl$EditorImpl.notifyListeners(SharedPreferencesImpl.java:612)
        at android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:598)
        at com.jggdevelopment.simpleweather.fragments.MasterFragment.updateConditions(MasterFragment.java:263)
        at com.jggdevelopment.simpleweather.services.WeatherAPIUtils$2.onResponse(WeatherAPIUtils.java:92)
        at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1$1.run(DefaultCallAdapterFactory.java:83)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7319)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
Run Code Online (Sandbox Code Playgroud)

java android android-fragments

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

如何使用 Kotlin 延迟加载协程刷新 ViewModel 数据?

我正在尝试在我正在构建的天气应用程序中实现 SwipeToRefreshLayout。当用户滑动刷新时,应该更新ViewModel中的数据,然后相应地更新视图。

这是我的 CurrentWeatherFragment 的片段:

override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel = ViewModelProviders.of(this, viewModelFactory)
                .get(WeatherResponseViewModel::class.java)

        pullToRefresh.setOnRefreshListener(this)

        bindUI()
    }

    override fun onRefresh() {
        viewModel = ViewModelProviders.of(this, viewModelFactory)
                .get(WeatherResponseViewModel::class.java)

        bindUI()
        pullToRefresh.isRefreshing = false
    }

    private fun bindUI() = launch {
        val currentWeather = viewModel.weather.await()
        currentWeather.observe(this@CurrentWeatherFragment, Observer {
            if (it == null) return@Observer

            loading_icon.visibility = View.GONE

            updateLocation("Raleigh")
            updateDateToToday()
            updateTemperatures(it.currently.temperature.roundToInt(),
                    it.currently.apparentTemperature.roundToInt(),
                    it.daily.data[0].temperatureMin.roundToInt(),
                    it.daily.data[0].temperatureMax.roundToInt())
            updateDescription(it.currently.summary)
            updateEnvironmentals((it.currently.humidity * 100).roundToInt(), it.currently.windSpeed.roundToInt())
            updateWeatherIcon(it.currently.icon)
            updateTempChart(it)
            updatePrecipChart(it)
        })
    }
Run Code Online (Sandbox Code Playgroud)

我的视图模型:

class WeatherResponseViewModel (
        private val forecastRepository: ForecastRepository,
        unitProvider: UnitProvider …
Run Code Online (Sandbox Code Playgroud)

android coroutine kotlin kotlin-coroutines

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