Mata-i grasa _|_
RST  

Go Back   RST > >> 1337 Zone << > Programare

Programare Coltul programatorilor

Reply
Old 01-29-2010, 11:31 AM   #1 (permalink)
Registered Users
Cultul betivilor
 
Gonzalez's Avatar
 
Join Date: Sep 2006
Location: Europe
Posts: 1,000
Rep Power: 5
Gonzalez se balangane pe drum
Gonzalez is offline

Default Working With Images In Android


Basic Android Image Information

Android supports 3 common image formats PNG, JPG, GIF, along with [Doar userii inregistrati pot vedea linkurile. ]. Images are stored in the directory res/layout/drawable. As of version 1.6 of the Android SDK multiple drawable directories exist for different screen resolutions. There are low, medium, and high DPI specific directories, drawable-ldpi, drawable-mdpi, drawable-hdpi respectively. This allows you to create images at different DPI to enhance the appearance of your application. All image filenames should be lowercase and only contain letters, numbers, and underscores.

Create a new project in Eclipse called TestImages.

Displaying An Image

The ImageView layout component is the base element used for displaying images in Android. Download this [Doar userii inregistrati pot vedea linkurile. ] and copy it into res/layout/drawable-mdpi in your project. We're simply going to use a screenshot of the emulator.

Code:
<ImageView 
   android:id="@+id/test_image"
   android:src="@drawable/test"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   />

This ImageView loads the image test that you downloaded. Add this to the res/layout/main.xml file below the TextView.

Code:
package higherpass.TestImages;

import android.app.Activity;

public class TestImages extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.test_image);
    }
}

All that was added to the default code is how to get the ImageView component from the layout and store it in a variable. We'll do more with this in the next examples.

Changing The Image

Changing the image done by creating an ImageView object for the image component to change and calling the setImageResource() method. Instead of using resources a custom bitmap can also be used by invoking setImageBitmap(). We'll get to bitmaps next. Download this [Doar userii inregistrati pot vedea linkurile. ] and store it as test2.png in res/layout/drawable-mdpi.

Code:
package higherpass.TestImages;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class TestImages extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.test_image);
        image.setImageResource(R.drawable.test2);
    }
}

Here simply store the ImageView into the image variable and use the setImageResource() method to point the ImageView at the second image.
__________________

Warez to da b0ne





  Reply With Quote
Sponsored Links
Reply

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump




Copywr0ng (c) 2009 Miercuri catre Joi - RST
All logos and trademarks in this site are property of their respective

Hosted by powerhost.ro