gpt4 book ai didi

android - android中的右滑二级菜单

转载 作者:行者123 更新时间:2023-11-29 18:02:50 24 4
gpt4 key购买 nike

我从 here 得到了滑动菜单库,我不知道这里有什么问题,在这个右侧的幻灯片菜单中出现但它是空白的。这是代码

// customize the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setMode(SlidingMenu.LEFT_RIGHT);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
//sm.setTouchModeAbove(SlidingMenu.LEFT_RIGHT);



getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

这是我调用secondarymenu的方式

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
showSecondaryMenu();

return true;
}
return super.onOptionsItemSelected(item);
}
}

这是我实例化 fragment 的方式。

setContentView(R.layout.activity_home_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.home_screen, new MapFragment())
.commit();

getSlidingMenu().setSecondaryMenu(R.layout.activity_home_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.home_screen, new MapFragment())
.commit();

// set the Behind View
setBehindContentView(R.layout.activity_settings_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_screen, new SettingsFragment())
.commit();

我的 map fragment

public class MapFragment extends SherlockFragment{

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_map, null);
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

}

}

设置 fragment

public class SettingsFragment extends SherlockFragment{

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_settings, null);
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

}

}

设置布局

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

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Settings view."
></TextView>
</LinearLayout>

map 布局

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

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your map "
></TextView>
</LinearLayout>

请告诉我为什么右侧菜单空白?

最佳答案

它成功了,问题是。而不是这个

 getSlidingMenu().setSecondaryMenu(R.layout.activity_home_frame);

我要打电话

getSlidingMenu().setSecondaryMenu(getLayoutInflater().inflate(R.layout.activity_map, null));

关于android - android中的右滑二级菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14973954/

24 4 0