我通过以下代码将drawable放入edittext中:
final Drawable x = getResources().getDrawable(R.drawable.del2);
x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight());
atxt.setCompoundDrawables(null, null, x, null);
使用此代码我的drawable显示在edittext的右侧,我想为它设置边距。例如,如果我设置rightMargin:20dp我的drawable稍微偏向左侧。我怎么能这样做?
答案 0 :(得分:0)
你有没有试过像:
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom);
x.setLayoutParams(lp);