How to Open Java Images in Android

Android development uses the "LinearLayout" XML layout to define and image for your Android app. After you create the LinearLayout, you call the image in your Java code to display it on the Android device. Each image is given an ID, which lets you store several images in the XML file and open each one individually in the code.

Instructions

    • 1

      Open the Eclipse software on your desktop and open the Android app project to open all of the files in the editor.

    • 2

      Double-click the "main.xml" file in the "resource" directory. This file is where you place your XML images and layout. Add the following code to add an image to the app:

      <LinearLayout
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
      <ImageButton
      android:background="@null"
      android:id="@+id/myimage"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/myimage" />
      </LinearLayout>

      The "myimage" ID is the image you want to use from the list of Java project images.

    • 3

      Open the view and display the image in your app. The following code opens the "main.xml" file and displays the image:

      setContentView(R.layout.main);

Related Searches:

References

Comments

Related Ads

Featured