android - 片段中可绘制的进度
问题描述
我是android开发的新手,正在做一个项目。当图像被加载时,我试图在我的片段中添加一个 circulaprogressdrawable。但它根本没有加载。当我不使用 Fragment 并且在活动中包含代码时,它曾经可以工作。有人可以告诉我我做错了什么吗?欢迎任何建议。谢谢。以下是供参考的代码
package com.example.demoauthfirebase
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.swiperefreshlayout.widget.CircularProgressDrawable
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
/**
* A simple [Fragment] subclass.
*/
class FragmentImage : Fragment() {
companion object {
const val ARG_NAME = "urlVal"
fun newInstance(urlVal: String): FragmentImage {
val fragment = FragmentImage()
val bundle = Bundle().apply {
putString(ARG_NAME, urlVal)
}
fragment.arguments = bundle
return fragment
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val activity = activity as Context
var circularProgressDrawable = CircularProgressDrawable(activity)
circularProgressDrawable.strokeWidth = 10f
circularProgressDrawable.centerRadius = 50f
circularProgressDrawable.setColorSchemeColors(Color.GREEN)
circularProgressDrawable.start()
val view: View = inflater.inflate(
R.layout.fragment_fragment_image, container,
false
)
val imgView = view.findViewById<ImageView>(R.id.imgView1)
val urlVal = arguments?.getString(ARG_NAME)
val options = RequestOptions().placeholder(circularProgressDrawable)
options.fitCenter()
Glide.with(activity)
.load(urlVal)
.apply(options)
.override(1200, 3000)
.into(imgView)
// Inflate the layout for this fragment
return view
}
}
解决方案
这个是我自己修好的。我使用的图像视图没有明确提到宽度和高度。当我添加它时,它开始出现。不知道这是否是最好的答案,但它似乎有效。下面是fragment.xml的代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FragmentImage">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="100dp"
android:paddingRight="10dp"
android:paddingBottom="200dp">
<ImageView
android:id="@+id/imgView1"
android:layout_width="338dp"
android:layout_height="255dp"
android:scaleType="center"
android:visibility="visible"
tools:visibility="visible"></ImageView>
</LinearLayout>
</FrameLayout>
推荐阅读
- nstableview - 通过上下文菜单隐藏 NSTableView(或 NSOutlineView)列:“无代码”解决方案
- javascript - 从 getBoundingClientRect 赋值
- reactjs - 找不到模块:无法解析“C:\Users\Syndicate\Documents\GitHub\simserp\sims\src\components\modules\country”中的“@mui/x-data-grid”
- java - 下载文件,防止网络错误删除
- algorithm - 为什么要使选择排序稳定?
- php - 如何禁止选择值出现并且只看到回显结果
- python - 我应该怎么做才能将多个 ctypes 数据类型分配给 Python 中的单个 ctypes 实例?
- c++ - 第 1034 行:字符 9:运行时错误:引用绑定到类型为 'std::vector 的空指针
在 leetcode 上运行以下代码时出现运行时错误。当我删除用户定义的比较器功能时,它工作正常。但是使用用户定义的比较器函数,它会给出运行时错误,如下所示:
第 1034 行:字符 9:运行时错误:引用绑定到类型为“std::vector<int, std::allocator>”的空指针 (stl_vector.h) 摘要:
- python - gcc 找不到文件,即使它在包含路径上
- reactjs - 如何在 resctjs 打字稿中的谷歌地图上绘制多边形