在片段中使用毕加索更改图像视图内容
Change image view content using picasso in a fragment
从昨天开始,我尝试将 imageView 的内容更改为片段,但按钮很漂亮,但它什么也没做。
如有任何帮助,我将不胜感激
片段中使用的方法:
override fun onClick(v: View?) {
when (v?.id) {
R.id.nextButton -> {
// val rnds = (0..99999).random()
val quest1 = "https://My-web-get-image-url.com/"
// var randomGetNumber = quest1 + rnds
Picasso.get().load(quest1).memoryPolicy(MemoryPolicy.NO_CACHE).into(memeRandomView)
Picasso.get().setLoggingEnabled(true)
}
else -> {
}
}
}
}
我的布局
<ImageView
android:id="@+id/memeRandomView"
android:layout_width="385dp"
android:layout_height="452dp"
android:layout_marginStart="32dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="32dp"
android:src="@drawable/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/memeRandomView"
app:layout_constraintVertical_bias="0.434" />
在使用 findViewById(),viewBinding,kotlin-ext 获得视图 (nextButton,memeRandomView) 的参考后,您可以设置这样的点击并在点击监听器中使用 picasso:
nextButton.setOnClickListener{
Picasso.get()
.load(url)
.centerCrop()
.into(memeRandomView)
}
从昨天开始,我尝试将 imageView 的内容更改为片段,但按钮很漂亮,但它什么也没做。
如有任何帮助,我将不胜感激
片段中使用的方法:
override fun onClick(v: View?) {
when (v?.id) {
R.id.nextButton -> {
// val rnds = (0..99999).random()
val quest1 = "https://My-web-get-image-url.com/"
// var randomGetNumber = quest1 + rnds
Picasso.get().load(quest1).memoryPolicy(MemoryPolicy.NO_CACHE).into(memeRandomView)
Picasso.get().setLoggingEnabled(true)
}
else -> {
}
}
}
}
我的布局
<ImageView
android:id="@+id/memeRandomView"
android:layout_width="385dp"
android:layout_height="452dp"
android:layout_marginStart="32dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="32dp"
android:src="@drawable/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/memeRandomView"
app:layout_constraintVertical_bias="0.434" />
在使用 findViewById(),viewBinding,kotlin-ext 获得视图 (nextButton,memeRandomView) 的参考后,您可以设置这样的点击并在点击监听器中使用 picasso:
nextButton.setOnClickListener{
Picasso.get()
.load(url)
.centerCrop()
.into(memeRandomView)
}