滑动菜单而不移动标题



我正在我的应用程序中创建一个滑动菜单抽屉...问题是当我滑动菜单时,它也在滑动标题,我只想让内容随着滑块移动。如何防止标头移动。我正在为我的代码使用片段:

主要活动 :

setContentView(R.layout.layout_home);
        ButterKnife.inject(this);
        btnMenu.setVisibility(View.VISIBLE);
        homeScreenFragment = new HomeScreenFragment();
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.frameLayout, homeScreenFragment).commit();
        // configure the SlidingMenu menu = new SlidingMenu(this);
        menu=new SlidingMenu(this);
        menu.setShadowDrawable(R.drawable.shadow);
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        menu.setFadeDegree(0.35f);
        menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        menu.setMenu(R.layout.menu_frame);
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.menu_frame, new HomeNavFragment()).commit();
        findViewById(R.id.imgBtnMenu).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                menu.toggle(true);
            }
        });

首页屏幕片段:

public final String[] podName = new String[] { "NO Text", "NO Text",
            "NO Text", "NO Text" };
    public final Integer[] images = { R.drawable.pod_img1, R.drawable.pod_img2,
            R.drawable.pod_img3, R.drawable.pod_img1 };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_homescreen, container,
                false);
        ButterKnife.inject(this, view);
        return view;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        addItemsToListView();
    }
    private void addItemsToListView() {
        rowItems = new ArrayList<RowItem>();
        for (int i = 0; i < podName.length; i++) {
            RowItem item = new RowItem(images[i], podName[i]);
            // RowItem item = new RowItem(imageUrl[i], deityName[i]);
            rowItems.add(item);
        }
        setAdapter();
    }
    private void setAdapter() {
        CustomBaseAdapter adapter = new CustomBaseAdapter(getActivity(), rowItems);
        podListView.setAdapter(adapter);
    }
    Navigation Fragment: 
public static final String[] nav_title = new String[] { "CLE & Events",
                "Pictorial Roster", "Publications", "On-Demand CLE", "Court Info",
                "LBA Alerts", "My Profile", "Notification Settings",
                "App Support & Feedback", "Share this App", "Developer", " ", " " };
        public static final int[] nav_icon = { R.drawable.ic_menu_calender,
                R.drawable.ic_menu_roster, R.drawable.ic_menu_publication,
                R.drawable.ic_menu_filebox, R.drawable.ic_menu_court,
                R.drawable.ic_menu_bubble, R.drawable.ic_menu_profile,
                R.drawable.ic_menu_reminder, R.drawable.ic_menu_share,
                R.drawable.ic_menu_developer, R.drawable.ic_menu_developer,
                R.drawable.ic_menu_developer };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_homescreen, container,
                false);
        ButterKnife.inject(this, view);
        return view;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        setAdapter();
        /*addItemsToListView();*/
    }

    private void setAdapter() {
        NavigationMenuAdapter adapter = new NavigationMenuAdapter(getActivity(),nav_title,nav_icon);
        podListView.setAdapter(adapter);
    }

Xml:

layout_home:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <include
            android:id="@+id/header_home"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            layout="@layout/include_header" />
        <FrameLayout 
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/header_home">
        </FrameLayout>
    </RelativeLayout>

layout_homescreen

    <ListView
        android:id="@+id/podListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="@android:color/transparent"
        android:listSelector="@android:color/transparent" >
    </ListView>
</LinearLayout>
menu.xml

由于您想使用侧面板 + ActionBar 移动内容区域应该保持静态,最好的方法是实现 v4 小部件 SlidingPaneLayou t (android.support.v4.widget.SlidingPaneLayout)。

这是一个很好的例子,解释了如何实现SlidingPaneLayout。

请浏览开发者网站进行正确理解。

希望对您有所帮助..!! :)

最新更新