I am stocked on the following code.var x = this.FindViewById<RelativeLayout>(Resource.Id.container); foreach (var item in feedItemsList) { LinearLayout linearLayout = this.FindViewById<LinearLayout>(Resource.Id.linear); linearLayout.FindViewById<TextView>(Resource.Id.title).Text = item.Title; x.AddView(linearLayout); }
the linear layout is:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="horizontal" android:id="@+id/linear"> <FrameLayout android:layout_width="300dp" android:layout_height="300dp" android:gravity="center"> <ImageView android:id="@+id/imazhi" android:layout_width="300dp" android:layout_height="300dp" android:gravity="center" android:src="@drawable/Icon" android:contentDescription="" android:layout_gravity="center" /> <TextView android:id="@+id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Titolo" android:textColor="#ffffff" android:textSize="16dp" android:gravity="bottom" android:textStyle="bold" android:layout_gravity="bottom" /> </FrameLayout> </LinearLayout>
And the relative layout is:<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/container"> </RelativeLayout>
Answers
If the
LinearLayout
you are trying to add to theRelativeLayout
isn't in the currently set content view, then you won't be able to useFindViewById
to find it. Then you need to use aLayoutInflater
to inflate the layout and add it.Although. It could seem like you are trying to make a list of items of some sort, you might want to consider using a
RecyclerView
orListView
and use anAdapter
to populate it.All this is described in the documentation.
Yes it can be done using
LIstView
byadapter
to populate the items but I want the items to be stacked one on top of other so currently I am usingRelativeLayout
but if you have some better idea then suggest with code which will be hlpful to me.I also need to rotate the
LinearLayout
to some angle dynamically please add some code which will help me