problem in image reading

Put your problem here if it does not fit any of the other categories.

problem in image reading

Postby ekambresh » Thu Feb 14, 2008 1:00 pm

hey all, i am new to android, trying to draw image in the background.,and placed image in drawable folder,
i am using following code but it giving "cannot resolve drawable".and even R.java file is not updating, i am using eclips IDE, i dont know wt is happening.
plz guide me how to draw image and wt saught of alteration has to be done to xml file

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent"
  10.  
  11.    >
  12.  
  13. <TextView  
  14.  
  15.    android:layout_width="fill_parent"
  16.  
  17.    android:layout_height="wrap_content"
  18.  
  19.    android:text="Hello World, Draw"
  20.  
  21.    />
  22.  
  23. <ImageView
  24.  
  25.         id = "@+id/image"
  26.  
  27.         android:layout_centerVertical = "true"
  28.  
  29.         android:layout_centerHorizontal = "true"
  30.  
  31.         android:layout_width = "fill_parent"   
  32.  
  33.         android:layout_height = "fill_parent"
  34.  
  35.         android:src = "@drawable/image1">
  36.  
  37. </ImageView>
  38.  
  39. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.android.draw;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.widget.ImageView;
  10.  
  11.  
  12.  
  13. public class Draw extends Activity {
  14.  
  15.     /** Called when the activity is first created. */
  16.  
  17.     @Override
  18.  
  19.     public void onCreate(Bundle icicle) {
  20.  
  21.         super.onCreate(icicle);
  22.  
  23.         setContentView(R.layout.main);
  24.  
  25.         ImageView image = new ImageView(this);
  26.  
  27.         image.setImageDrawable(getResources(R.drawable.image1));
  28.  
  29.         image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  30.  
  31.        
  32.  
  33.        
  34.  
  35.     }
  36.  
  37. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


best Regards
ekambresh
ekambresh
ekambresh
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Feb 08, 2008 8:54 am
Location: Bangalore

Top

Postby plusminus » Thu Feb 14, 2008 1:04 pm

Hello ekambresh,

are you using the sdk release yesterday :?:
Then you need to change
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.      id = "@+id/image"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

to
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.      android:id = "@+id/image"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


also in this line:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ImageView image = new ImageView(this);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

you were thinking of doing this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ImageView image = (ImageView)findViewById(R.id.image);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


You should also change that one codeline to the following:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ...setImageDrawable(getResources().getDrawable(R.drawable.image));
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 12 guests