使用jfeinstein10库滑动菜单 [英] sliding menu using jfeinstein10 library
问题描述
我创建了一个示例应用程序来测试滑动菜单的工作原理。在下面的截图显示的是我所得到的,作为现在。但是,当我点击的类别按钮(如下图所示),我应该得到一个二级菜单如下图所示的zomato应用程序的屏幕截图。我怎样才能做到这一点?我是否继续以正确的方式或不?
我SlidingFragmentActivity:
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
CON =这一点;
setSlidingActionBarEnabled(假);
的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(滑条);
//设置背后查看
setBehindContentView(R.layout.menu_frame);
FragmentTransaction T = this.getSupportFragmentManager()
.beginTransaction();
mFrag =新SampleListFragment();
t.replace(R.id.menu_frame,mFrag);
t.commit();
}
我SampleListFragment:
公共类SampleListFragment扩展SherlockFragment {
私有静态最后的String [] Radio_buttons =新的String [] {距离,
等级 };
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
捆绑savedInstanceState){
查看查看= inflater.inflate(R.layout.list,集装箱,假);
ListView控件radio_list =(ListView控件)view.findViewById(R.id.RadioList);
按钮类别=(按钮)view.findViewById(R.id.sampleButton);
radio_list
.setAdapter(新ArrayAdapter<字符串>(MainActivity.con,
android.R.layout.simple_list_item_single_choice,
Radio_buttons));
radio_list.setItemsCanFocus(真正的);
radio_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
categories.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
MainActivity.sm.showSecondaryMenu();
}
});
返回查看;
}
}
main.xml中
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。>
<的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:文本=滑动菜单演示... !!! />
< / RelativeLayout的>
menu_frame.xml
< XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / menu_frame
机器人:layout_width =match_parent
机器人:layout_height =match_parent/>
list.xml
< XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /滚轮
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:fillViewport =真正的>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:后台=#FFFFFF
机器人:以下属性来=10dp
机器人:文本=搜索
机器人:文字颜色=#FF3300
机器人:TEXTSIZE =20dp>
< / TextView的>
< / LinearLayout中>
< RelativeLayout的
机器人:ID =@ + ID / searchTextLayout
机器人:layout_width =match_parent
机器人:layout_height =50dip
机器人:layout_marginBottom =20dip
机器人:layout_marginLeft =20dip
机器人:layout_marginRight =20dip
机器人:layout_marginTop =20dip>
<的ImageButton
机器人:ID =@ + ID / searchTextButton
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =match_parent
机器人:layout_alignParentLeft =真
机器人:后台=#685E5C
机器人:scaleType =fitCenter
机器人:SRC =@可绘制/ abs__ic_search/>
<的EditText
机器人:ID =@ + ID / searchText
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_toRightOf =@ ID / searchTextButton
机器人:背景=@可绘制/ background_black_border_full
机器人:填充=8DP
机器人:文字颜色=@机器人:彩色/白/>
< / RelativeLayout的>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
<的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:后台=#FFFFFF
机器人:以下属性来=10dp
机器人:文本=排序
机器人:文字颜色=#FF3300
机器人:TEXTSIZE =20dp>
< / TextView的>
< / LinearLayout中>
< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =134dp>
<的ListView
机器人:ID =@ + ID /单选列表
机器人:layout_width =match_parent
机器人:layout_height =FILL_PARENT>
< / ListView控件>
< / RelativeLayout的>
<按钮
机器人:ID =@ + ID / sampleButton
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文本=分类/>
< / LinearLayout中>
< /滚动型>
SlidingMenu并没有这样做,zomato使用自定义实现。
SlidingMenu会让你有一个菜单中的离开和右,但不是两个两边。
我想看看使用视图寻呼机或自定义实现。 EitherWay我不知道的东西开箱做到这一点。我可能是值得考虑的的Android浏览的灵感。
I created a sample application to test how sliding menu works. Shown below in the screenshot is what i get as of now. But when I click on the categories button (shown in image below) I should get a secondary menu as shown in the zomato app's screenshot below. How can I do this ? Am I proceeding in the correct way or not?
my SlidingFragmentActivity :
@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();
}
my SampleListFragment :
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;
}
}
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>
SlidingMenu does NOT do this, zomato uses a custom implementation.
SlidingMenu will let you have a menu on the left and the right, but not two on either side.
I would look at using a view pager or a custom implementation. EitherWay I don't know of anything out of the box to do this. I might be worth looking at Android Views for inspiration.
这篇关于使用jfeinstein10库滑动菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!