2017-10-27 3 views
0

レイアウト内に描画可能なボトムとしてボタンが設定されたラジオボタンを取得しました。 Javaで私はsetCompoundDrawablesWithIntrinsicBounds(0,R.drawable.wrong,0,R.drawable.check);メソッドでdrawable topを設定し、drawable topは表示されません。ラジオボタンの描画可能な上端がsetCompoundDrawablesWithIntrinsicBounds()で表示されません。 setButtonDrawable()を使用します。間違った位置に表示される

setButtonDrawable();でラジオボタンdrawablebottomを変更していない別の方法を試しましたが、これは良いですし、ボタンの隣の位置に描画可能を設定しています。

image

位置を上に変更するにはどうすればよいですか?

答えて

0

あなたがで描画可能な下を維持するために、あなたの前の描画可能を再利用することができます

Drawable drawableTop = ContextCompat.getDrawable(getContext(),R.drawable.wrong); 
//Drawable drawableBottom = ContextCompat.getDrawable(getContext(),R.drawable.check); 

Drawable[] drawables = button.getCompoundDrawables(); 
// left top right bottom 
button.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawableTop, drawables[2], drawables[3]); 

それとも、次のことを試すことができます。

Drawable drawableTop = ContextCompat.getDrawable(getContext(),R.drawable.wrong); 
Drawable drawableBottom = ContextCompat.getDrawable(getContext(),R.drawable.check); 

int topHeight = drawableTop.getIntrinsicHeight(); 
int topWidth = drawableTop.getIntrinsicWidth(); 
drawableTop.setBounds(0, 0, topWidth, topHeight); 

topHeight = drawableBottom.getIntrinsicHeight(); 
topWidth = drawableBottom.getIntrinsicWidth(); 
drawableBottom.setBounds(0, 0, topWidth, topHeight); 

button.setCompoundDrawables(null, drawableTop, null, drawableBottom); 
関連する問題