Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在视图寻呼机中打开视图时感到困惑_Java_Android_Adapter_Layout Inflater - Fatal编程技术网

Java 在视图寻呼机中打开视图时感到困惑

Java 在视图寻呼机中打开视图时感到困惑,java,android,adapter,layout-inflater,Java,Android,Adapter,Layout Inflater,我正在尝试使用SimpleViewPager和Pager适配器开发一个基本的imageView滑块 因此,首先我将查看寻呼机放在我的主要活动中。我正在尝试开发一个视图寻呼机,它有一个简单的布局,其中包含两个图像 下面是我的image\u view\u simple.xml文件: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayo

我正在尝试使用SimpleViewPager和Pager适配器开发一个基本的imageView滑块

因此,首先我将查看寻呼机放在我的主要活动中。我正在尝试开发一个视图寻呼机,它有一个简单的布局,其中包含两个图像

下面是我的
image\u view\u simple.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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:id="@+id/imageViewActionThumbnail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:elevation="100dp"
    android:visibility="gone"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:srcCompat="@drawable/ic_launcher_background" />

</android.support.constraint.ConstraintLayout>
但是在上面的例子中,当我在适配器中创建
visibility=true
时,输出在第一张幻灯片中没有显示
imageViewActionThumbnail
(我甚至尝试在所有幻灯片中默认从XML显示它,但它没有显示!)

因此,我创建了一个单独的文件
temp.xml
,它只有一个子文件TextView,并添加代码将其膨胀并附加到视图中。像这样

// Same code as above, just add the below two lines inside instantiateItem() method.

View view1 = LayoutInflater.from(context).inflate(R.layout.temp, view, false);
view.addView(view1);

container.addView(view);
return view;
输出显示每张幻灯片中的imageView(左上角),如下图所示。

我想知道:

1:为什么图像视图在第一种情况下不显示?为什么我需要对另一个布局进行充气并将其添加到父布局中

2:如果我想在不膨胀任何其他布局的情况下显示两个imageView,该怎么办

// Same code as above, just add the below two lines inside instantiateItem() method.

View view1 = LayoutInflater.from(context).inflate(R.layout.temp, view, false);
view.addView(view1);

container.addView(view);
return view;