When you are create Complex design in your project , that time making a  view hierarchy tree taller will also result in slowness in your application and increases complexity. Creating optimized layouts is fundamental to building an application that runs fast and is responsive to the user. use <include/> tag in your xml to resolve this situation.we are discuss with example-

1)create a file in drawable folder “performance_view.xml”

<pre><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txt_author"
    android:layout_marginTop="10dp">
    <ImageView
        android:id="@+id/lbl_view"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:src="@drawable/activity_blog_view" />
    <TextView
        android:id="@+id/txt_view"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lbl_view"
        android:layout_marginLeft="5dp"
        android:text="10,00" />

    <ImageView
        android:id="@+id/lbl_comment"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/lbl_view"
        android:src="@drawable/activity_blog_comment" />
    <TextView
        android:id="@+id/txt_comment"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lbl_comment"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/txt_view"
        android:text="100"
        android:gravity="center"/>
    <ImageView
        android:id="@+id/lbl_like"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/lbl_comment"
        android:src="@drawable/activity_blog_like" />
    <TextView
        android:id="@+id/txt_like"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lbl_comment"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/txt_comment"
        android:text="999"
        android:gravity="center"/>
    <ImageView
        android:id="@+id/lbl_share"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/lbl_like"
        android:src="@drawable/activity_blog_share" />

    <TextView
        android:id="@+id/txt_share"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lbl_share"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/txt_like"
        android:gravity="center"
        android:text="10" />
    <ImageView
        android:id="@+id/lbl_google"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/lbl_share"
        android:src="@drawable/activity_blog_googleplus" />
    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lbl_google"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/txt_share"
        android:gravity="center"
        android:text="10" />
</RelativeLayout>


</pre>

include example
2) create a file in drawable folder “layout_performance.xml”

<pre><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:orientation="vertical">
    <TextView
        android:id="@+id/txt_post"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Create a Re-usable Layout"
        android:textSize="25sp"
        android:textColor="@android:color/black"/>
    <TextView
        android:id="@+id/txt_author"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ester"
        android:layout_below="@+id/txt_post"
        android:textSize="19sp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"/>

<span style="color: #ff0000;"><strong><span style="text-decoration: underline;"><include layout="@layout/activity_blogger_view"></include>
</span></strong></span>
    </LinearLayout></pre>

Result:

include example in android

Advertisements