Android 使用jfeinstein10库的滑动菜单
我创建了一个示例应用程序来测试滑动菜单是如何工作的。下面的截图是我现在得到的。但当我点击categories按钮(如下图所示)时,我应该会看到一个辅助菜单,如下面zomato应用程序的屏幕截图所示。我该怎么做?我是否以正确的方式进行 我的幻灯片片段活动:Android 使用jfeinstein10库的滑动菜单,android,slidingmenu,Android,Slidingmenu,我创建了一个示例应用程序来测试滑动菜单是如何工作的。下面的截图是我现在得到的。但当我点击categories按钮(如下图所示)时,我应该会看到一个辅助菜单,如下面zomato应用程序的屏幕截图所示。我该怎么做?我是否以正确的方式进行 我的幻灯片片段活动: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); con
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
con = this;
setSlidingActionBarEnabled(false);
setContentView(R.layout.main);
sm = getSlidingMenu();
sm.setMode(SlidingMenu.RIGHT);
sm.setShadowDrawable(R.drawable.shadowright);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
sm.setBehindScrollScale(1.0f);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.5f);
//sm.setSecondaryMenu(R.layout.properties);
//sm.setSecondaryShadowDrawable(R.drawable.shadow);
setTitle("Sliding Bar");
// set the Behind View
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = this.getSupportFragmentManager()
.beginTransaction();
mFrag = new SampleListFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
}
我的样本列表片段:
public class SampleListFragment extends SherlockFragment {
private static final String[] Radio_buttons = new String[] { "Distance",
"Rating" };
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list, container, false);
ListView radio_list = (ListView) view.findViewById(R.id.RadioList);
Button categories = (Button) view.findViewById(R.id.sampleButton);
radio_list
.setAdapter(new ArrayAdapter<String>(MainActivity.con,
android.R.layout.simple_list_item_single_choice,
Radio_buttons));
radio_list.setItemsCanFocus(true);
radio_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
categories.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.sm.showSecondaryMenu();
}
});
return view;
}
}
公共类SampleListFragment扩展了SherlockFragment{
私有静态最终字符串[]单选按钮=新字符串[]{“距离”,
“评级”};
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图=充气机。充气(R.layout.list,容器,假);
ListView radio_list=(ListView)view.findViewById(R.id.RadioList);
按钮类别=(按钮)视图.findViewById(R.id.sampleButton);
电台节目表
.setAdapter(新阵列适配器)(MainActivity.con,
android.R.layout.simple\u list\u item\u单选,
单选按钮);
radio_list.setItemsCanFocus(真);
radio_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
categories.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
MainActivity.sm.showSecondary菜单();
}
});
返回视图;
}
}
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Sliding menu demo...!!!" />
</RelativeLayout>
menu_frame.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
list.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SEARCH"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:id="@+id/searchTextLayout"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_marginBottom="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip" >
<ImageButton
android:id="@+id/searchTextButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#685E5C"
android:scaleType="fitCenter"
android:src="@drawable/abs__ic_search" />
<EditText
android:id="@+id/searchText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/searchTextButton"
android:background="@drawable/background_black_border_full"
android:padding="8dp"
android:textColor="@android:color/white" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SORT BY"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="134dp" >
<ListView
android:id="@+id/RadioList"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
<Button
android:id="@+id/sampleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Categories" />
</LinearLayout>
</ScrollView>
滑动菜单不执行此操作,zomato使用自定义实现 通过滑动菜单,您可以在左侧和右侧各有一个菜单,但两侧不能有两个
我将考虑使用视图寻呼机或自定义实现。我不知道有什么现成的方法可以做这件事。我可能值得一看以寻求灵感。虽然有点晚了,但还是让我发布我的答案,以防它对将来的人有所帮助。如果要显示另一个菜单,可以使用
setMode(SlidingMenu.LEFT_RIGHT);
setSecondaryMenu(R.layout.yourSecondMenu);
点击你的按钮
showSecondaryMenu(true);
并在该类中执行您的操作。您想展示什么?右菜单?@Ahmad ya右菜单。看到上面的第一个屏幕截图,当我点击“categories”按钮时,我应该会在上面看到一个新的滑动菜单,如第二个屏幕截图(zomato应用程序)所示。