Created
August 29, 2013 02:07
-
-
Save emil10001/6373553 to your computer and use it in GitHub Desktop.
SlidingPaneLayout for Android, blog post here: http://www.recursiverobot.com/post/59642335041/trying-slidingpanelayout-with-fragments-in-android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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