我在ViewFlipper中添加了2个图像视图,但是没有图像显示。设置View Flipper的背景颜色时,会显示颜色,但不会投影任何图像。这是一个非常基础的项目。请告诉我原因。我同时附有Java和XML文件,请看看
MainActivity.java
public class MainActivity extends AppCompatActivity {
ViewFlipper viewFlipper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper = findViewById(R.id.viewFlipper);
viewFlipper.setAutoStart(true);
viewFlipper.setFlipInterval(3000);
viewFlipper.startFlipping();
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context=".MainActivity">
<ViewFlipper
android:id="@+id/viewFlipper"
android:layout_width="match_parent"
android:layout_height="281dp"
android:inAnimation="@anim/right_to_left"
android:outAnimation="@anim/right_to_left"
android:background="@color/colorPrimaryDark"
android:padding="10dp"
android:visibility="visible">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:scaleType="fitXY"
android:layout_height="wrap_content"
app:srcCompat="@drawable/f2" />
</ViewFlipper>
</android.support.constraint.ConstraintLayout>