Java 从布局中保存2个ImageView

Java 从布局中保存2个ImageView,java,android,kotlin,download,imageview,Java,Android,Kotlin,Download,Imageview,我正在申请拼贴式的申请。我的问题是,我有一个按钮,以保存拼贴的2个图像,但他们没有保存。我已经尝试了很多代码两天了,但我找不到解决方案 这是具有2个图像视图的视图 [活动主图][1] [1]: https://i.stack.imgur.com/PrBY4.jpg <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayo

我正在申请拼贴式的申请。我的问题是,我有一个按钮,以保存拼贴的2个图像,但他们没有保存。我已经尝试了很多代码两天了,但我找不到解决方案

这是具有2个图像视图的视图

[活动主图][1] [1]: https://i.stack.imgur.com/PrBY4.jpg

 <?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:id="@+id/L1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<ImageSwitcher
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="36dp"
    app:layout_constraintBottom_toTopOf="@+id/prev"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />

<Button
    android:id="@+id/prev"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="44dp"
    android:layout_marginTop="36dp"
    android:text="@string/prev"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.434" />

<Button
    android:id="@+id/prev2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="44dp"
    android:layout_marginTop="36dp"
    android:text="@string/prev"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.975" />

<Button
    android:id="@+id/next"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="41dp"
    android:layout_marginEnd="36dp"
    android:text="@string/next"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toEndOf="@+id/prev"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.429" />

<Button
    android:id="@+id/next2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="36dp"
    android:layout_marginEnd="36dp"
    android:layout_marginBottom="16dp"
    android:text="@string/next"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toEndOf="@+id/prev"
    app:layout_constraintTop_toBottomOf="@+id/imgSw" />

<Button
    android:id="@+id/btn_download"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:text="@string/download"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<ImageSwitcher
    android:id="@+id/imageView2"
    android:layout_width="373dp"
    android:layout_height="202dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="36dp"
    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.858" />


</androidx.constraintlayout.widget.ConstraintLayout>

主要活动有2个带照片的幻灯片(旋转木马)。我希望当我按下下载按钮时,两张照片都会被保存

这类似于将布局转换为图像,但按钮不可见

     import android.os.Bundle
    import android.widget.Button
    import android.widget.ImageSwitcher
    import android.widget.ImageView
    import androidx.appcompat.app.AppCompatActivity


class MainActivity : AppCompatActivity() {

    private val flowers = intArrayOf(
        R.drawable.flower1,
        R.drawable.flower2, R.drawable.flower4
    )
    private var index = 0


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        // access the ImageSwitcher
        val imgSwitcher = findViewById<ImageSwitcher>(R.id.imageView)

        imgSwitcher?.setFactory({
            val imgView = ImageView(applicationContext)
            imgView.scaleType = ImageView.ScaleType.FIT_CENTER
            imgView.setPadding(8, 8, 8, 8)
            imgView
        })


        // set the method and pass array as a parameter
        imgSwitcher?.setImageResource(flowers[index])



        // previous button functionality
        val prev = findViewById<Button>(R.id.prev)
        prev.setOnClickListener {
            index = if (index - 1 >= 0) index - 1 else 2
            imgSwitcher?.setImageResource(flowers[index])
        }
        // next button functionality
        val next = findViewById<Button>(R.id.next)
        next.setOnClickListener {
            index = if (index + 1 < flowers.size) index +1 else 0
            imgSwitcher?.setImageResource(flowers[index])
        }


        // access the ImageSwitcher Two
        val imgSwitcher2 = findViewById<ImageSwitcher>(R.id.imageView2)

        imgSwitcher2?.setFactory({
            val imgView = ImageView(applicationContext)
            imgView.scaleType = ImageView.ScaleType.FIT_CENTER
            imgView.setPadding(8, 8, 8, 8)
            imgView
        })


        // Two previous button functionality
        val prev2 = findViewById<Button>(R.id.prev2)
        prev2.setOnClickListener {
            index = if (index - 1 >= 0) index - 1 else 2
            imgSwitcher2?.setImageResource(flowers[index])
        }
        // Two next button functionality
        val next2 = findViewById<Button>(R.id.next2)
        next2.setOnClickListener {
            index = if (index + 1 < flowers.size) index +1 else 0
            imgSwitcher2?.setImageResource(flowers[index])
        }


        //DOWNLOAD COLLAGE IMAGE

        val downloadButton = findViewById<Button>(R.id.btn_download)
        downloadButton.setOnClickListener {

        }

    }
}
导入android.os.Bundle
导入android.widget.Button
导入android.widget.ImageSwitcher
导入android.widget.ImageView
导入androidx.appcompat.app.appcompat活动
类MainActivity:AppCompatActivity(){
私人val flowers=intArrayOf(
R.drawable.flower1,
R.drawable.flower2,R.drawable.flower4
)
私人var指数=0
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//访问图像切换器
val imgSwitcher=findviewbyd(R.id.imageView)
IMG开关?设置工厂({
val imgView=ImageView(applicationContext)
imgView.scaleType=ImageView.scaleType.FIT\u CENTER
imgView.setPadding(8,8,8,8)
imgView
})
//将方法和传递数组设置为参数
imgSwitcher?.setImageResource(花卉[索引])
//上一个按钮功能
val-prev=findViewById(R.id.prev)
prev.setOnClickListener{
索引=如果(索引-1>=0)索引-1其他2
imgSwitcher?.setImageResource(花卉[索引])
}
//下一步按钮功能
val next=findViewById(R.id.next)
next.setOnClickListener{
索引=如果(索引+1=0)索引-1其他2
imgSwitcher2?.setImageResource(花卉[索引])
}
//两个下一步按钮功能
val next2=findViewById(R.id.next2)
next2.setOnClickListener{
索引=如果(索引+1