如何在android中的滑动菜单中添加横幅区域?

时间:2013-11-26 14:57:52

标签: android android-layout android-fragments slider

enter image description here

我目前正在使用https://github.com/jfeinstein10/SlidingMenu滑动菜单库。

从一个工作示例:https://github.com/baruckis/Android-SlidingMenuImplementation它在左侧菜单中使用列表片段。问题是,我想在列表顶部添加一个横幅区域,有什么方法可以实现吗? (比如他们在列表顶部有搜索框和用户信息的facebook)

我尝试在列表片段中使用添加标题视图,但我更喜欢该区域不可滑动并修复到顶部。感谢

下面的代码是列表片段类,其中R.layout.sliding_menu_holo_light_list是listview,所以看起来我无法自定义它

public class SlidingMenuListFragment extends ListFragment {
    protected List<SlidingMenuListItem> slidingMenuList;
    private SlidingMenuBuilderBase slidingMenuBuilderBase;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
            // We set here a custom layout which uses holo light theme colors.
            return inflater.inflate(R.layout.sliding_menu_holo_light_list, null);
    }

    public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);

            // We get a list from our specially created list data class.
            slidingMenuList = SlidingMenuList.getSlidingMenu(getActivity());
            if (slidingMenuList == null)
                    return;

            // We pass our taken list to the adapter.
            SlidingMenuListAdapter adapter = new SlidingMenuListAdapter(
                            getActivity(), R.layout.sliding_menu_holo_light_list_row, slidingMenuList);
            setListAdapter(adapter);
    }

    // We could define item click actions here, but instead we want our builder
    // to be responsible for that.
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
            l.setSelection(position);
            SlidingMenuListItem item = slidingMenuList.get(position);
            slidingMenuBuilderBase.onListItemClick(item);
    }

    // We can not provide a builder as an argument inside a fragment
    // constructor, so that is why we have separate method for that.
    public void setMenuBuilder(SlidingMenuBuilderBase slidingMenuBuilderBase) {
            this.slidingMenuBuilderBase = slidingMenuBuilderBase;
    }

}

1 个答案:

答案 0 :(得分:0)

导航抽屉的每个实现都有其自身的复杂性,但是大多数实现允许您为整个布局充气,这意味着您可以使用线性布局作为父级并包含列表片段(或您想要使用的任何其他内容) 。我没有读到提供的库但是我建议查看navigation drawer的googles实现。

作为一个注释:我实际上没有尝试过谷歌实现,当我实现一个导航抽屉时,它是在他们将它添加到支持库之前,所以我自己做了。