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.

  • Android Studio 2.3 Beta 1 + Support 25.1.0 = Preview broken
  • How to get all android contacts but without those which are on SIM
  • Android KitKat 4.4 folder on sd card
  • Android - not able to attach a file in email
  • Android Exif data in JPEG file
  • Android IAB. Error - Authentication is required. You need to sign into your Google Account
  • I want to add the layout into WebView

    Related posts:

    Calculating the angle between the line defined by two points
    How to set color for imageview in Android
    Phonegap Plugin:How to convert Base64 String to a PNG image in Android
    How to capture the screen as fast as possible through adb?
    How to check if SharedPreferences exists or not
    GSON : custom object deserialization
  • Android - How do i get sharedpreferences from another activity?
  • LocationServices.SettingsApi Reset SETTINGS_CHANGE_UNAVAILABLE flag
  • Android : Draw Circle With Text Inside
  • Detect application heap size in Android
  • How to uninstall an android app from command line on the device
  • What are the .db-shm and .db-wal extensions in Sqlite databases?
  • 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.