2014-04-30 44 views
0

即時嘗試設置右可拖動到TextView(在列表視圖的標題)。我設置了界限,但沒有幫助。 setDrawablesWithInstrinct綁定工作正常。 這裏是代碼:Android。 SetCompoundDrawables不起作用

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; 
} 

什麼問題?

+0

使用'setCompoundDrawablesWithIntrinsicBounds(NULL,NULL,d,NULL);' –

+0

要添加的填充,可以使用'機器人:drawablePadding =「8DP 「'in xml或'setCompoundDrawablePadding(12)'in Java。 –

回答

6

試試這個:

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);