add layout as a view in Android

I have a pretty complex layout defined in xml file , now I want to add this layout as a view using addView or something else.

As layout is pretty much complex , its pretty cumbersome process to write the code for layout and then add it as a view. So is there anyway to load layout resource and add it as a view.

  • Programmatically center TextView text
  • Phone Gap camera orientation
  • display huge Images in Android
  • How to change language Google Map V2 android
  • Andengine fade in/out and alpha modifiers not working
  • How to set a Fragment tag by code?
  • I want to add the layout into WebView

    Related posts:

    Kill another application on Android?
    Is it possible to use BitmapFactory.decodeFile method to decode a image from http location?
    Styling a AppCompatButton in v21 to have no shadow and corner radius of zero
    How to align title at center of ActionBar in default theme(Theme.Holo.Light)
    MEDIA_MOUNTED broadcast not being received
    Remove glare from photo opencv
  • ImageView: adjustViewBounds does not work with layout_height=“fill_parent”?
  • Degrees symbol (as in Degrees Celsius/Fahrenheit) in a TextView
  • How to debug “”
  • Force RTL layout direction not working for app
  • AutoStart Application not working properly
  • ExpandableListView Slide animation on Group expand/collapse
  • 3 Solutions collect form web for “add layout as a view in Android”


    LayoutInflater factory = LayoutInflater.from(this);
    View myView = factory.inflate(R.layout.my_layout_id, null);

    then use addView(myView)

    U can also reduce this to oneline code;

      View view = View.inflate(getActivity, R.layout.my_layout,null);

    then add to your view.

    If your view is a ViewGroup (layout)
    You can use InflaterService.inflate(id, ViewGroup) and set the ViewGroup, it will set the current child(s) with the content of your xml.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.