如何解决可包裹物体和使用图像视图
我需要有关使用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 举报,一经查实,本站将立刻删除。