开发者

How to center ListView footer horizontally

I've added a footer to my ListView like so:

...{
  listView.addFooterView(getButtonFooter(context));
...}

    private View getButtonFooter(Context context) {
        Button button = new Button(context);
        AbsListView.LayoutParams params = new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        button.setLayoutParams(params);
        button.setBackgroundResource(R.drawable.add_reminder_btn_selector);
        button.setId(ADD_REMINDER);
        button.setOnClickListener(this);
        return button;
    }

I'm trying to figure out how I can now center开发者_运维问答 the button horizontally.

EDIT: oh, maybe like this? button.setGravity(Gravity.CENTER_HORIZONTAL);

EDIT: lol, nope. That didn't seem to work. Guess that just center's the text inside the button...


LinearLayout layout = new LinearLayout(this);
        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        layout.setGravity(Gravity.CENTER_HORIZONTAL);
        Button button = new Button(this);
        button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        button.setBackgroundResource(R.drawable.add_reminder_btn_selector);
        button.setId(ADD_REMINDER);
        button.setOnClickListener(this);
        layout.addView(button);
        return layout;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜