Android系统。 SetCompoundDrawables不起作用

时间:2014-04-30 13:13:18

标签: android

我尝试将right-drawable设置为TextView(在列表视图的标题中)。我正在设置界限,但它没有帮助。 setDrawablesWithInstrinctBounds()工作正常。

这是代码:

private View getHeaderView() {
    final LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.legislation_article_list_header, null, false);
    final TextView textView = (TextView) view.findViewById(R.id.sEdition);
    headerSpinner = textView;

    final Drawable d = getActivity().getResources().getDrawable(R.drawable.spinner_arrow_down);
    d.setBounds(new Rect(0, 0, headerSpinner.getHeight(), headerSpinner.getHeight()));
    headerSpinner.setCompoundDrawables(null, null, d, null);

    textView.setOnClickListener(new View.OnClickListener() {

       .............

        }
    });
    return view;
}

有什么问题?

1 个答案:

答案 0 :(得分:8)

试试这个:

Drawable d = getActivity().getResources().getDrawable(R.drawable.spinner_arrow_down);
d.setBounds(new Rect(0, 0, headerSpinner.getHeight(), headerSpinner.getHeight()));
textView.setCompoundDrawablesWithIntrinsicBounds( d , null, null, null);

textView.setCompoundDrawablesWithIntrinsicBounds( R.drawable.smiley, 0, 0, 0);