可包裹物体和使用图像视图

问题描述

我需要有关使用Kotlin构建应用程序的帮助。 在其中,我实际上想单击一个图像,它将打开一个新窗口,并且我想使用Parcelable对象和范围函数来执行此操作。 xml和kotlin代码在下面。

<LinearLayout 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">


    <LinearLayout
        android:layout_width="207dp"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="match_parent"
            android:layout_height="283dp"
            android:clickable="true"
            app:srcCompat="@drawable/batman" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:text="batman" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="score:10/10" />

        <Space
            android:layout_width="match_parent"
            android:layout_height="21dp" />

    </LinearLayout>


</LinearLayout>

这是Activity_main.xml文件

<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"
    tools:ignore="MissingDefaultResource">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="413dp"
        android:layout_height="153dp"
        android:layout_marginBottom="71dp"
        app:layout_constraintBottom_toTopOf="@+id/textView10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/batman" />

    <TextView
        android:id="@+id/textView10"
        android:layout_width="281dp"
        android:layout_height="35dp"
        android:layout_marginStart="69dp"
        android:layout_marginTop="71dp"
        android:layout_marginEnd="61dp"
        android:layout_marginBottom="32dp"
        android:text="Batman"
        app:layout_constraintBottom_toTopOf="@+id/editTextDate"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <EditText
        android:id="@+id/editTextDate"
        android:layout_width="251dp"
        android:layout_height="29dp"
        android:layout_marginStart="100dp"
        android:layout_marginTop="40dp"
        android:layout_marginEnd="101dp"
        android:ems="10"
        android:inputType="date"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.268"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView10" />


</androidx.constraintlayout.widget.ConstraintLayout>

这是activity_main2.xml。

这些是我的xml文件,现在这里是我要记住的。我想将图像的数据作为Parcelable对象传递(例如,字符的出生日期,职业以及非文本视图对象中该字符的分数),并使用范围函数。当我在android studio中运行该应用程序时,我需要单击图像,该图像会将我带到原始页面的新页面(activity_main2),但是我不知道如何使用Parcelable对象,也不知道如何将图像视图实现为可点击新页面,也不能正确使用范围功能。 这是我目前所做的Kotlin代码

var HeroDetails = intent.getParcelableObject<String>("herodetails")
class Activityone : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_detail)

        foodDetails = intent.getParcelableExtra<HeroDetails>("herodetails")
        var foodImage = findViewById<ImageView>(R.id.ImageDetail)
        val image = intent.getExtras()
        if (image != null) {
            var resid = image.getInt("resId")
            batimage.setimageResource(resid)
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...