I am dynamically inflating following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
>
<ImageView
android:id="@+id/grid_img"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/nature3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_name"
android:text=",jfjgf xxfbdg fd dfhs lhl;fsfladsfh; jkhsdl;fshkjfl;fks; l;hflsaf"
android:inputType="textMultiLine"
android:maxLines="2"
android:ellipsize="end"
android:layout_alignBottom="@+id/grid_img"
android:layout_alignRight="@+id/grid_img"
android:layout_alignLeft="@+id/grid_img"
/>
</RelativeLayout>
I am adding this xml via inflation using following code.
RelativeLayout v = (RelativeLayout)inf.inflate(R.layout.ui_three, null);
Now the problem is I attributes defined in xml are ignored and I am getting followin UI on android phone.

I am getting textview aligned with top edge of image where as in xml it is aligned with bottom of the image.
Any solution to this problem.
Pass the parent layout to which you are going to add the new layout to as the second parameter:
The inflated layout will then inherit layout params from the parent. If you are getting errors when you then try to add the new layout to its parent, use an alternate
LayoutInflatormethod which allows you to stop the inflator from automatically attaching the new layout to the parent: