gpt4 book ai didi

android - 如何将多张图片上传到不同的 ImageView?

转载 作者:行者123 更新时间:2023-11-30 02:11:54 25 4
gpt4 key购买 nike

我需要将 2 张不同的图片上传到不同的图片 View 。如何上传?

这是我的 xml 示例文件。

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >

<ImageView
android:id="@+id/uivProfileImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:scaleType="fitXY" />

<ImageView
android:id="@+id/uivProfileCoverImage"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toRightOf="@+id/uivProfileImage"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:maxHeight="100dp"
android:scaleType="fitXY" />

</RelativeLayout>

最佳答案

使用请求码来区分点击了哪个ImageView,例如

Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(intent, PICK_FIRST_IMAGE);

其中 PICK_FIRST_IMAGE 是 int 值等于 100

Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(intent, PICK_SECOND_IMAGE);

其中 PICK_SECOND_IMAGE 是等于 101 的 int 值。

然后在 onActivityResult 中你可以这样做:

public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (resultCode == Activity.RESULT_OK) {

...

if(requestCode == PICK_FIRST_IMAGE)
firstImageView.setImageBitmap(yourSelectedImage);
else
secondImageView.setImageBitmap(yourSelectedImage);
}

关于android - 如何将多张图片上传到不同的 ImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29982820/

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