gpt4 book ai didi

android - 将图像从 ImageView 设置为 Dialog

转载 作者:行者123 更新时间:2023-11-29 18:35:43 25 4
gpt4 key购买 nike

我将一个字符串 url 从 fragment A 传递到 B,并加载到 imageView

if (obj?.signature_image?.url != null) {
Glide.with(activity)
.load(obj?.signature_image?.url.toString())
.into(imgSignature)
}

当点击imgSinature时,会弹出自定义对话框,我想在对话框中设置图片。我怎样才能实现?

signDialog = Util().dialogSignature(getActivity())

imgSignature.setOnClickListener {
signDialog.show()
if (obj?.signature_image?.url != null) {
signDialog.relativeLayout2.addView(obj?.signature_image?.url)
}
}

效用

fun dialogSignature(context: Context?):Dialog{

var dialog = Dialog(context)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setContentView(R.layout.dialog_signature)
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
return dialog

}

dialog_signature

<?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/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="230dp"
android:orientation="vertical"
android:background="@android:color/white">

<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content"
android:background="@color/colorPrimaryShadow"
android:orientation="horizontal"
android:id="@+id/linearLayout1"
android:gravity="center"
android:layout_marginBottom="2dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/relativeLayout2" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:layout_marginLeft="10dp"
android:layout_weight="0.4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Place Signature"
android:textSize="17sp"
android:layout_gravity="right"/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:id="@+id/doneTxt"
android:text="Done"
android:textColor="@color/colorDarkBlue"/>

</LinearLayout>

<RelativeLayout android:layout_width="0dp" android:layout_height="0dp"
android:id="@+id/relativeLayout2"
android:background="@color/colorWhite"
app:layout_constraintTop_toBottomOf="@+id/linearLayout1" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0">
</RelativeLayout>


<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:textColor="@color/colorDarkBlue"
android:text="Clear" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" app:layout_constraintHorizontal_bias="1.0"
android:layout_marginBottom="16dp" app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/clearTxt"/>

</android.support.constraint.ConstraintLayout>

此行 signDialog.relativeLayout2.addView(obj?.signature_image?.url) 错误

Type mismatch. Required: View! Found: String?

真的很烦....

It looks like your post is mostly code; please add some more details.

最佳答案

您试图将 url 字符串添加到错误的 View 中。在您的 relativeLayout2 中添加一个 ImageView 并使用 Glide 加载您的图片 url

<RelativeLayout 
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/relativeLayout2"
android:background="@color/colorWhite"
app:layout_constraintTop_toBottomOf="@+id/linearLayout1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0">

<ImageView
android:id="@+id/your_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

在你的onClick

imgSignature.setOnClickListener {
...
Glide.with(activity)
.load(obj?.signature_image?.url.toString())
.into(signDialog.your_image)
}

关于android - 将图像从 ImageView 设置为 Dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54457698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com