Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

display linear layout inside relative layout using c# android

soumyasambitKunda.6563soumyasambitKunda.6563 INMember
edited July 2015 in Xamarin.Android

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="" 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="" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/container"> </RelativeLayout>


  • CheesebaronCheesebaron DKInsider, University mod

    If the LinearLayout you are trying to add to the RelativeLayout isn't in the currently set content view, then you won't be able to use FindViewById to find it. Then you need to use a LayoutInflater 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 or ListView and use an Adapter to populate it.

    All this is described in the documentation.

  • Yes it can be done using LIstView by adapterto populate the items but I want the items to be stacked one on top of other so currently I am using RelativeLayout 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

Sign In or Register to comment.