Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 图像在图像视图中不可见_Java_Android - Fatal编程技术网

Java 图像在图像视图中不可见

Java 图像在图像视图中不可见,java,android,Java,Android,我的xml文件如下所示,当我选择图像时,光标会选择图像 但是图像没有出现在我的图像视图中 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_p

我的xml文件如下所示,当我选择图像时,光标会选择图像 但是图像没有出现在我的图像视图中

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingBottom="16dp"
    android:paddingTop="16dp"
    tools:context="com.appsound.instagram.memeappgenerator.MainActivity">
    <EditText
        android:id="@+id/editTop"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:hint="@string/entertopmemetext" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:hint="@string/enterbottommemetext"
        android:id="@+id/editBottom"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="@string/add_image"
        android:textSize="20sp"
        android:background="#F44336"
        android:textColor="#000"
        android:onClick="addImage"
        />
    <Button
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="TRY"
        android:textSize="20dp"
        android:background="#E1F5"
        android:textColor="#FFFFFF"
        android:onClick="trymeme" />

    <RelativeLayout
        android:id="@+id/lay"
        android:layout_width="match_parent"
        android:layout_height="250dp">

        <ImageView
            android:id="@+id/memeImage"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:src="@mipmap/ic_launcher"
            android:visibility="visible" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/meme_top_text"
            android:layout_centerHorizontal="true"
            android:textColor="#FFFFFF"
            android:id="@+id/memeTopText"
            android:textAlignment="center"
            android:textSize="30dp" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/memeBottomText"
            android:layout_centerHorizontal="true"
            android:text="@string/meme_bottom_text"
            android:textAlignment="center"
            android:textColor="#FFFFFF"
            android:textSize="30dp"
            android:layout_alignParentBottom="true"/>

    </RelativeLayout>
    <Button
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="@string/save"
        android:textSize="20sp"
        android:background="#F44336"
        android:textColor="#000"
        android:onClick="saveImage"/>
</LinearLayout>

图像视图上的图像上载有很大问题,图像上载按钮工作正常并获取图像,但图像无法显示在图像视图am堆栈上。请帮帮我,我会很高兴的。谢谢你

试试这个活动结果

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();

            imgView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

        }


    }

从ActivityResult开始尝试此操作

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();

            imgView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

        }


    }

代码工作得像奇迹谢谢我的老板谢谢代码工作得像奇迹谢谢我的老板谢谢谢谢