Search code examples
androidlayoutpngjpeg

Using JPEG as background on Android instead of PNG


I want to ask if Android accepts JPEG images instead of PNG, because PNG has bigger file size than JPEG.

I want to know how to use JPEG as background image in layout.xml file. Can you help me?


Solution

  • Just put a .jpg file in your res/drawable folder and refer to it as you normally would.

    For example, if you put picture.jpg in your drawable folder, from one of your views you could just do the following.

    <View
        android:id="@+id/view_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/picture" />