i'm facing a problem in my android project . Here I have a imageButton , on click of this I have to inflate a layout file and dynamically add it inside a Relative layout . adding view is working perfectly . but the problem is after adding this child view I need move the image button below the new child layout . but my imageButton is inflating under the child view , maybe I'm missing some LayoutParameters and rules .
here are my code
private void addDestinationViews() {
View destinationChildView = LayoutInflater.from(getActivity()).inflate(R.layout.destination_city_item, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_TOP, R.id.add_destinationbutton);
destinationChildView.setLayoutParams(params);
mInflated_view_holder.addView(destinationChildView);
}
here is the layout i want to inflate
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/add_destination_button_back"
android:text="afaf"
android:textSize="18sp"
android:paddingLeft="30dp"
android:padding="10dp"
android:gravity="start|center"/>
<ImageButton
android:id="@+id/cancle_destination_imagebutton"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="@drawable/cross_place_icon"
android:scaleType="centerInside"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"/>
this is the relative layout which will host the inflated layout
<RelativeLayout
android:id="@+id/inflated_view_holder_three"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/child_counter_title"
android:layout_marginTop="15dp">
<ImageButton
android:id="@+id/add_destinationbutton"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/add_place_icon"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:background="@drawable/add_destination_button_back"/>
</RelativeLayout>
P.S I forget to mention this child view will be added upon the imageButton press . so the code needs to be dynamic here .