ImageView没有在Xiomi智能手机中显示图像

时间:2017-12-01 14:53:44

标签: android

我编写了一个程序来浏览图库,并使用AndroidStudio在ImageView中显示所选图像。我有Select Image From Gallery And Display It On ImageView, Issue On Nexus 5

的示例代码

它正在运行良好的股票Android运行智能手机像LG L70集。但在Xiomi 4A的imageview上看不到任何图像。

对于实验,我在Eclipse编辑器中编写了相同的代码。 Eclipse开发的代码运行良好,LG L70和Xiomi 4A。

因此,很明显代码不是问题。问题必须来自IDE。你能帮我解决这个问题吗?我应该在哪里修改代码,以便它可以在AndroidStudio开发的Xiomi上运行。

Codes in gdrive.

代码

package com.example.nasif.xiomi_imageview2;


import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;


import static android.widget.Toast.LENGTH_LONG;

public class MainActivity extends AppCompatActivity
{
    private ImageView imgProfile;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imgProfile = (ImageView)findViewById(R.id.imgProfileIV);

        final Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                // Perform action on click
                //new MyAsyncTask(this).execute("ppppp");
                Log.d("MyTag", "1");
                ImageProfile();
            }
        });
    }

    public void ImageProfile()
    {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 100);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent)
    {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

        switch(requestCode)
        {
            case 100:
                if(resultCode == RESULT_OK)
                {
                    Uri selectedImage = imageReturnedIntent.getData();
                    imgProfile.setImageURI(selectedImage);
                    Log.d("MyTag", "@: " + selectedImage);
                    Toast.makeText(MainActivity.this, "@: " + selectedImage, LENGTH_LONG).show();

                }
        }
    }

}

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.nasif.xiomi_imageview2">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.nasif.xiomi_imageview2.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <ImageView
        android:id="@+id/imgProfileIV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/a"
        android:onClick="ImageProfile" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/imgProfileIV"
        android:text="Button" />

</RelativeLayout>

0 个答案:

没有答案
相关问题