android textview填充父级

时间:2010-07-15 20:14:17

标签: android background textview

我有一个简单的ExpandalbeList。对于组标题视图,我使用的是简单的TextView,我将文本的背景设置为drawable。我将textview参数设置为FILL_PARENT,但TextView的背景仅覆盖文本的宽度。我意识到我可以把它全部放在线性布局中,但这似乎是浪费。是不是有办法让文本视图的边界延伸到列表视图的边缘?

        public TextView getGenericView() {
        // Layout parameters for the ExpandableListView
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, 64);

        TextView textView = new TextView(PulseSearchResults.this);
        textView.setLayoutParams(lp);
        // Center the text vertically
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
        // Set the text starting position
        textView.setPadding(6, 0, 0, 0);
        textView.setTextColor(Color.BLACK);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        textView.setTextSize(16.0f);
        textView.setBackgroundResource(R.drawable.search_section_group);
        return textView;
    }
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        TextView textView = getGenericView();
        textView.setText(getGroup(groupPosition).toString());
        return textView;
    }

THX 本

1 个答案:

答案 0 :(得分:0)

我只是想通了如果我将listview的宽度设置为FILL_PARENT,它就解决了问题......