如何在SwipeMenuListView中

时间:2017-03-16 13:58:33

标签: java android

我正在使用库 com.baoyz.swipemenulistview 每件事情都很好我想要每个菜单项周围的边框,这样即使所有菜单项背景都是白色,每个菜单项周围都有一个灰色边框项目相互分离。

在查看代码后,我发现可以在 SwipeMenuView.java

的以下功能中实现
private void addItem(SwipeMenuItem item, int id) {
    LayoutParams params = new LayoutParams(item.getWidth(),
            LayoutParams.MATCH_PARENT);
    LinearLayout parent = new LinearLayout(getContext());
    parent.setId(id);
    parent.setGravity(Gravity.CENTER);
    parent.setOrientation(LinearLayout.VERTICAL);
    parent.setShowDividers(LinearLayout.SHOW_DIVIDER_BEGINNING);
    parent.setLayoutParams(params);
    parent.setBackgroundDrawable(item.getBackground());
    parent.setOnClickListener(this);
    addView(parent);

    if (item.getIcon() != null) {
        parent.addView(createIcon(item));
    }
    if (!TextUtils.isEmpty(item.getTitle())) {
        parent.addView(createTitle(item));
    }

}

由于我是Android世界的新手,我无法找到在菜单项周围绘制边框的方法。在LinearLayout中要查找哪些具有绘制边框功能的函数/方法。或如何如图所示绘制边框

Ide:Android Studio 2.2.3

enter image description here

链接到图书馆: SwipeMenuListView Github

更新

我已将 GradeintDrawable 添加到该功能现在边框已存在,但此处我无法传递将返回的 item.getBackground Drawable )。如何使用 item.getBackground 设置 GradientDrawable.setColor(int color); ,这将返回 Drawable ;

private void addItem(SwipeMenuItem item, int id) {
    LayoutParams params = new LayoutParams(item.getWidth(),
            LayoutParams.MATCH_PARENT);



    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setStroke(1, Color.BLACK);
    drawable.setCornerRadius(1);

    //drawable.setColor(Color.GRAY); here i have to pass item.getBackground();

     //like :
       drawable.setColor(item.getBackground); //error because getBackground is of type drawable;


    LinearLayout parent = new LinearLayout(getContext());
    parent.setId(id);
    parent.setGravity(Gravity.CENTER);
    parent.setOrientation(LinearLayout.HORIZONTAL);
    parent.setLayoutParams(params);
    //parent.setBackgroundDrawable(item.getBackground());
    parent.setBackgroundDrawable(drawable);
    parent.setOnClickListener(this);
    addView(parent);

    if (item.getIcon() != null) {
        parent.addView(createIcon(item));
    }
    if (!TextUtils.isEmpty(item.getTitle())) {
        parent.addView(createTitle(item));
    }

}

0 个答案:

没有答案