How would I embed an image into a view?

All your problems with Audio, Video and Images.

How would I embed an image into a view?

Postby SolidSora » Thu Oct 14, 2010 2:07 am

I'm trying to embed my image into my main view, but I can't find a way to get it to work right. What would I need to post in my XML or my main program to embed an image in there?

Edit: I want to use an image that I put in my res directory.
SolidSora
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Oct 12, 2010 12:56 am

Top

Re: How would I embed an image into a view?

Postby Sathasivan » Thu Oct 14, 2010 8:59 am

use like this,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:background="#808000"
android:layout_height="fill_parent"
>


<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/icon"></ImageView>

</LinearLayout>
Last edited by Sathasivan on Thu Oct 14, 2010 2:49 pm, edited 1 time in total.
User avatar
Sathasivan
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Wed Oct 14, 2009 7:51 am
Location: Chennai

Re: How would I embed an image into a view?

Postby blundell » Thu Oct 14, 2010 1:22 pm

Clean your code up man!
main.xml
Code: Select all
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
  android:id="@+id/ImageView01"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/icon"/>
</LinearLayout>


@drawable is a reference to the res/drawable folder

Main.class
Code: Select all

public class Main extends Activity {
  @Override
    public void onCreate(Bundle savedInstanceState) {       
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
    }
}
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 33 guests