Skip to content

Instantly share code, notes, and snippets.

@emil10001
Created August 29, 2013 02:07
Show Gist options
  • Save emil10001/6373553 to your computer and use it in GitHub Desktop.
Save emil10001/6373553 to your computer and use it in GitHub Desktop.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
...
/>
<!-- The main content view
based on code from:
http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/ -->
<android.support.v4.widget.SlidingPaneLayout
android:id="@+id/pane"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/pane1"
android:layout_width="360dp"
android:layout_height="match_parent"
android:background="#CC00FF00" />
<FrameLayout
android:id="@+id/pane2"
android:layout_width="400dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#CC0000FF" />
</android.support.v4.widget.SlidingPaneLayout>
<!-- More stuff not included-->
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"
android:layout_gravity="center" />
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// details omitted
mPane = (SlidingPaneLayout) findViewById(R.id.pane);
mPane.openPane();
getSupportFragmentManager().beginTransaction()
.add(R.id.pane1, new PaneOneFrag(), "pane1").commit();
getSupportFragmentManager().beginTransaction()
.add(R.id.pane2, new PaneTwoFrag(), "pane2").commit();
}
// PaneTwoFrag is nearly identical, so it is omitted
public class PaneOneFrag extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frags, container, false);
v.setBackgroundColor(Color.RED);
TextView tv = (TextView)v.findViewById(R.id.textView);
tv.setText("Pane One");
return v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment