Wie man Bild von der url der website in der Bildansicht in android

Ich versuche, Bild-in-Bildansicht aus der url der website, aber das Bild nicht so zeigen,
Was ist falsch in diesem code?
Dies ist die url der Bild.

Ist es meine Haupttätigkeit

ImageView i;
private Bitmap bitmap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    i=(ImageView)findViewById(R.id.ImageView1);




    bitmap=GetBitmapfromUrl("http://test-dashboard1.seeloz.com/system/images/products_images/86/5454544114_1401886223?1401886223");
    i.setImageBitmap(bitmap);


}


public Bitmap GetBitmapfromUrl(String scr) {
    try {
        URL url=new URL(scr);
        HttpURLConnection connection=(HttpURLConnection)url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input=connection.getInputStream();
        Bitmap bmp = BitmapFactory.decodeStream(input);
        return bmp;



    } catch (Exception e) {
        //TODO Auto-generated catch block
        e.printStackTrace();
        return null;

    }
}}

in der XML-Datei

<RelativeLayout 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: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=".MainActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="85dp"
        android:layout_marginTop="179dp"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

meine AndroidManifest

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.image.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
  • Was ist das Ergebnis von GetBitmapfromUrl Funktion?
  • Sollten Sie veröffentlichen Sie Ihre logcat mit Fehlern und stack-traces. Sie werden wahrscheinlich haben eine NetworkOnMainThreadExceptio. Setzen Sie Ihren code in einen AsyncTask oder thread. Außerdem internet-Berechtigung zu manifestieren.
  • Könnte Sie klären die Frage?
  • Auch kann ich nicht wirklich sehen, ein Bild von der von Ihnen angegebenen url. Ist die url korrekt.
InformationsquelleAutor user3798394 | 2014-07-02
Schreibe einen Kommentar