Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android How to add view at start of layout?

Tags:

android

view

My question is simple. I have a linearlayout. It has some child views. Now I want to add a view at the start of the child. Means in normal addView(view), the view s added at the end of the layout. But I want to add it at start, at first position. Any idea...???

like image 363
Khawar Raza Avatar asked Dec 09 '11 09:12

Khawar Raza


People also ask

How do I add a view to activity?

This example demonstrates How to Dynamically Add Views into View. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is 0dp in android?

Equal distribution To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout).

How do I add a view in another view?

All you need to do is inflate the view programmatically and it as a child to the FrameLayout by using addChild() method. Then during runtime your view would be inflated and placed in right position. Per Android recommendation, you should add only one childView to FrameLayout [link].

What is addView?

The addView method, is used to add a View programmatically to a ViewGroup . A ViewGroup can be for example, a LinearLayout , or a RelativeLayout .. A ViewGroup is itself a View . The addView method is overloaded.


1 Answers

Use addView (View child, int index) with index = 0

like image 113
a.ch. Avatar answered Oct 02 '22 12:10

a.ch.