我想为我的 Android 应用程序设计 Evernote 之类的滑动菜单,其中包括滑动菜单中的 Gridview 和 Listview 内容。
我在slidingMenu 布局文件中实现了两个frameLayout,一个用于Gridview,另一个用于Listview。这是它的xml文件。
menu_frame.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/grid_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/menu_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/grid_frame"/>
</RelativeLayout>
id:menu_frame 的列表视图 Framelayout xml 文件
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/list_padding"
android:paddingRight="@dimen/list_padding" />
id:grid_frame 的 Gridview Framelayout xml 文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/list_padding"
android:paddingRight="@dimen/list_padding">
<!-- android:id="@+id/grid_list" -->
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="51dp"
android:layout_marginTop="81dp"
android:text="Grid Layout"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
最后这里是滑动菜单的java代码:SlideMenuBaseActivity.java
public class SlideMenuBaseActivity extends SlidingFragmentActivity{
private int mTitleRes;
protected SherlockListFragment mFrag;
protected SherlockFragment mFragGrid;
public SlideMenuBaseActivity(int titleRes) {
// TODO Auto-generated constructor stub
mTitleRes = titleRes;
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
setBehindContentView(R.layout.menu_frame);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new SlidingMenuFragment();
mFragGrid = new SlidingGridFragment();
FragmentTransaction t2 = this.getSupportFragmentManager().beginTransaction();
t2.replace(R.id.grid_frame, mFragGrid);
t2.commit();
t.replace(R.id.menu_frame, mFrag);
//t.replace(R.id.grid_frame, mFragGrid);
t.commit();
} else {
mFrag = (SherlockListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
mFragGrid = (SherlockFragment)this.getSupportFragmentManager().findFragmentById(R.id.grid_frame);
}
// customize the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}
我已经实现了上面的代码,但滑动菜单上只有 grid_view 内容可见,而 List_view 内容不可见。任何人都可以建议我一个解决方案来获得完整视图,例如使用我的应用程序片段的evernote滑动菜单.....
谢谢