0
我有一個TextView,我想使用setCompoundDrawablesWithIntrinsicBounds在其中添加一些drawable,問題是當我這樣做時,文本移動並且未對齊到一個沒有的TextView可繪製的。當使用setCompoundDrawablesWithIntrinsicBounds時,TextView會移動使用setCompoundDrawablesWithIntrinsicBounds
TextView tv1 = new TextView();
TextView tv2 = new TextView();
Drawable icon = getContext().getResources().getDrawable(
R.drawable.arrow_right_down,null);
tv1.setPadding(ARROW_PADDING,0,0,0);
tv1.setCompoundDrawablesWithIntrinsicBounds(
icon, null, null, null);
tv1.setText("A");
tv2.setText("A");
問題 - A's沒有對齊。如果我刪除drawable文本是對齊的。 TextViews位於另一個附近,所以很容易看到它。
謝謝。
你是怎麼想到要發生什麼?那就是,你現在想完成什麼,你知道會發生什麼? –
@MikeM。我只想要文本被分配:) – Mojo
那麼,你可以添加一個相同大小的透明'Drawable'到另一個。或者你可以得到'icon'的寬度,並將其添加到另一個的左邊填充。或者你可以左移另一個「TextView」的寬度。等等我可能會和第二個一起去。 –