从昨天开始,我试图将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)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句