Simple nine-patch generator for android studio chat - Joklinz-Tech

Latest

Home Of Tech news,jobs and android tutorials

Monday 5 February 2018

Simple nine-patch generator for android studio chat



What is Android Chat Bubble

This is a chat layout where two users message each other and a dynamic ListView is created on each message. Size of each bubble is automatically increases and reduced according to length of message. This is done through 9 patch Image.

What is 9 Patch Image

While designing a User Interface, one may wish to change the background to give app an innovative look. In this situation background should be scaled correctly otherwise a blurred image will be produced. Android uses Nine Patch files to provide support for scaling of backgrounds as View sizes change. For Example: In the image below second image is blurred at the edges, but if we use 9 patch then image will be scaled uniformly to fit in the long text as shown in third one.

    Generate 9 patch image

    First of all, we have to generate a 9 patch image which will be shown as bubble in android chat layout. Simplest method to generate 9 patch image is to use Android Asset Studio Simple Nine-patch Generator. This is a very handy tool to create simple 9 patch images for all dpi with a clean user interface. For now you can download following two images and save it in drawable folder (at path …/AndroidChatBubble/app/src/main/res/drawable/)
    <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/bubble_in"
            android:orientation="vertical"
            android:paddingBottom="10dp">
            <TextView
                android:id="@+id/txt_msg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxWidth="100dp"
                android:padding="5dp"
                android:textColor="@android:color/holo_red_dar"/>
        </LinearLayout>

No comments:

Post a Comment