2013-03-06 23 views
6

Tôi đã tạo một ứng dụng mẫu để kiểm tra cách trình đơn trượt hoạt động. Hiển thị bên dưới trong ảnh chụp màn hình là những gì tôi nhận được từ bây giờ. Nhưng khi tôi nhấp vào nút danh mục (được hiển thị trong hình ảnh bên dưới), tôi sẽ nhận được menu phụ như được hiển thị trong ảnh chụp màn hình của ứng dụng zomato bên dưới. Tôi có thể làm cái này như thế nào ? Tôi đang tiến hành đúng cách hay không?trình đơn trượt sử dụng thư viện jfeinstein10

enter image description here

enter image description here

SlidingFragmentActivity tôi:

@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(); 
    } 

SampleListFragment tôi:

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> 
+0

Bạn muốn hiển thị những gì? Menu bên phải? – Ahmad

+0

@Ahmad ya menu bên phải. xem ảnh chụp màn hình đầu tiên ở trên, khi tôi nhấp vào nút "danh mục" ở đó, tôi sẽ nhận được một trình đơn trượt mới trên đầu trang như được hiển thị trong ảnh chụp màn hình thứ hai (ứng dụng zomato). –

Trả lời

3

SlidingMenu KHÔNG làm điều này, sử dụng một zomato thực hiện tùy chỉnh.

TrượtMenu sẽ cho phép bạn có một menu trên bên tráibên phải, nhưng không hai ở hai bên.

Tôi sẽ xem xét sử dụng máy nhắn tin chế độ xem hoặc triển khai tùy chỉnh. Hoặc là tôi không biết bất cứ điều gì ra khỏi hộp để làm điều này. Tôi có thể đáng xem Android Views để lấy cảm hứng.

3

Hơi muộn một chút, nhưng vẫn để tôi đăng câu trả lời trong trường hợp nó sẽ giúp ai đó trong tương lai. Nếu bạn muốn hiển thị menu khác, bạn có thể sử dụng

setMode(SlidingMenu.LEFT_RIGHT); 
setSecondaryMenu(R.layout.yourSecondMenu); 

và nút bấm của bạn

showSecondaryMenu(true); 

và thực hiện các hành động của bạn trong lớp đó.

Các vấn đề liên quan