I want to use a command like this:
ImageView image = (ImageView) findViewById(R.id.x2);
where should I put in the file main.xml
the following piece of code?
<ImageView
android:id="@+id/x2"
android:src="@drawable/book"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
If you're working with an Android application, this source code works as a way to load an image from a file: Bitmap bitmap = BitmapFactory. decodeFile(pathToPicture);
Just one single method will let you to bring your view to the front and the magic words are : myView. bringToFront(); “.
For example, you can make an ImageView act like a simple Button by adding android:onClick to the ImageView . In this task you make the images in your layout clickable.
There's no differences, except default style.
Dheeresh Singh is ok. 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" >
<ImageView
android:id="@+id/x2"
android:src="@drawable/book"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
If you want to position the image in a different place, you can modify different attributes
<ImageView
android:id="@+id/x2"
android:src="@drawable/book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="42dp" <!--for example -->
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="25dp"/>
For more information about this, look at the android tutorials
http://developer.android.com/reference/android/widget/ImageView.html (for ImageView attributes) http://developer.android.com/resources/tutorials/views/index.html (for view info)
Excuse me for my english. Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With