【发布时间】:2021-02-10 12:14:09
【问题描述】:
我正在开展一个项目,在该项目中我使用 library 创建了一个轮播。
我还想在 TextView 中显示图像描述,该描述应该随着图像的变化而变化。 随着图像的变化,我无法更改 TextView。我应该怎么做才能做到这一点?
我的 Java 代码:
public class Carousel extends AppCompatActivity {
CarouselView carouselView;
int[] sampleImages = {R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_devs);
carouselView = findViewById(R.id.carouselView);
carouselView.setPageCount(sampleImages.length);
carouselView.setImageListener(imageListener);
}
ImageListener imageListener = (position, imageView) -> imageView.setImageResource(sampleImages[position]);
我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/retro_red"
tools:context=".AboutDevs">
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/pragya"
android:text="@string/about_devs"
android:textColor="@color/white"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.074" />
<com.synnapps.carouselview.CarouselView
android:id="@+id/carouselView"
android:layout_width="400dp"
android:layout_height="450dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5"
app:layout_constraintVertical_bias="0.235" />
</androidx.constraintlayout.widget.ConstraintLayout>
我知道这可能是一个愚蠢的问题,但我无法弄清楚。我将不胜感激。
【问题讨论】:
标签: java android text carousel