Saturday, September 20, 2014

4i. Android: 9patch

If you want to provide a reach UI you will be using images, it is not possible to create image for every device size, therefore they will be stretching. Android 9patch is a way to control what can stretch in the image to preserve quality of that image.

Examples of using 9patch:





Finding draw9patch tool 



In the browser search for square icon




  • top - stretch horizontally
  • left - stretch vertically
  • right - content area
  • bottom - content area





Actual look of the 9patch:



Copy your 9patch  pop_up_background_82x82.9.png to drawable folder:

conventer/src/main/res/drawable-mdpi/pop_up_background.9.png


    <TextView
            android:id="@+id/resultingValue"
            android:text="..."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="60"
            android:background="@drawable/pop_up_background" />