Skip to content Skip to sidebar Skip to footer

Inflate A Layout Inside Other Layout's Linearlayout

I've got this Layout: ComposeView http://img845.imageshack.us/img845/2121/d6zp.png The 2 borders (left,right )are filled by icons. When I touch one of these icons I access to other

Solution 1:

Hey use the following structure. put. include your common layout in each and every activity layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


<!-- Show top black custom title bar-->
<include 
    android:id="@+id/ll_top"
    layout="@layout/custom_tittlebar"
    android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</include>



<include 
    android:id="@+id/ll_left"
    layout="@layout/custom_left"
    android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >


</include>
<include 
    android:id="@+id/ll_right"
    layout="@layout/custom_right"
    android:layout_alignParentRight="true"
android:layout_centerVertical="true" >
</include>

<Button
    android:id="@+id/btn_center"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="center"
    android:layout_toRightOf="@+id/ll_left"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/ll_top"
    ></Button>
</RelativeLayout>

Solution 2:

You can have one main activity like BaseActivity that is extended by FragmentActivity. Base activity extends SlidingFragmentActivity and implements basic structure like menu etc. FragmentActivity onCreate method is :

@Override

public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);

                      fm = getSupportFragmentManager();
                      //This is main content that is switchable
                      mContent = new MainListActivity();  


                       //Additionally you can define those two lines as fragments and add them as default on both sides :
                      sideFragments = new sideFragments(this); 
                      FragmentTransaction ft = fm.beginTransaction();
                      ft.replace(R.id.content_frame, mContent);
                      ft.replace(R.id.side_framgments, sideFragments);
                      ft.commit();
                  }

When you press some of those buttons from your menu(left and right border) you will change the fragment in middle of the screen with this function in FragmentActivity :

  public void switchContent(Fragment fragment, String tag) {
        mContent = fragment;
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,fragment).addToBackStack(tag).commit(); 


  }

Note R.id.content_frame is the XML that is switchable between those two lines (let say menus on both sides) and R.id.side_framgments are those two lines in between the main layout that is switchable.


Post a Comment for "Inflate A Layout Inside Other Layout's Linearlayout"