2012-04-26 44 views
1

我想在android.The顯示一個圖像的過程是我從網上下載1圖像,並試圖顯示它在屏幕上,我面臨的問題是在活動屏幕我無法設置內容視圖和image.Following是代碼:在android中的dispalying圖像

的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

活動屏幕:

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.);---->Here i cant set as main 

     Bitmap bitmap = DownloadImage(
       "http://www.allindiaflorist.com/imgs/arrangemen4.jpg"); 
      ImageView img = (ImageView) findViewById(R.id.); //here i cant set the image id 
      img.setImageBitmap(bitmap); 

    } 

回答

0

清潔您的project.sometimes它不採取R. java文件。

3

使用Android智能圖像視圖。這是使用URL顯示圖像的最簡單方法。這裏是link

+0

任何生活教程?我無法從這個URL http://loopj.com/android-smart-image-view/ – 2014-07-12 11:25:26

0

只需使用Project - > Clean清理項目。如果它仍然存在,運行該項目,它們通常會消失。

+0

得到它的工作我清理了項目並運行了,但它顯示了在運行之前修復了項目中的問題。 – subburaj 2012-04-26 04:55:20

+0

是嗎?您在Android中經常遇到此類錯誤。嘗試重新啓動eclipse,或者創建一個新項目然後粘貼。嘿嘗試點擊Ctrl + Shift + o並且您的錯誤可能被解決 – nithinreddy 2012-04-26 05:12:55