私のアプリケーションでは、テキストビューに画像を表示する必要があります。また、最初にクリックすると1つの画像が描画され、次にクリックすると別の画像が描画されます。テキストビューで画像を描画することはできますか?助けてください。
4169 次
5 に答える
3
使用できます
setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
textViewの場合
于 2012-07-23T09:41:15.857 に答える
2
android:background
属性を使用して背景画像を設定できます
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image" />
またはプログラムでsetBackgroundDrawable()
またはsetBackgroundResource()
メソッドを使用して:
textView.setBackgroundResource(R.drawable.image);
于 2012-07-23T09:37:38.260 に答える
1
そのためのインデックスであるDrawablesの配列を取ることができます。
TextView tv;
Drawable[] drbl = new Drawable[4];
int drblIndex = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
drbl[0] = getResources().getDrawable(R.drawable.ic_launcher);
drbl[1] = getResources().getDrawable(R.drawable.img2);
drbl[2] = getResources().getDrawable(R.drawable.img3);
drbl[3] = getResources().getDrawable(R.drawable.right_arrow);
tv = (TextView) findViewById(R.id.textView1);
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv.setBackgroundDrawable(drbl[drblIndex++]);
if(drblIndex == drbl.length)
drblIndex = 0;
}
});
}
次に、私が行ったように、その配列の値を設定できます。
次に、onClickを使用して次のインデックスに移動し、新しいDrawable-ImageをTextViewに設定できます。
インデックスが最後の値に達したら、単純にゼロに設定します。
于 2012-07-23T09:48:38.973 に答える
0
OnClickListener
TextViewとそのメソッドで設定し、onClick()
次のメソッドを使用して画像を設定します。
textview.setBackgroundDrawable();
また
textview.setBackgroundResource();
于 2012-07-23T09:42:24.243 に答える
0
このコード、画像付きのテキストビューを試してください。
CharSequence dogstate = null; Html.fromHtml( "" + ""+"あなたのテキスト"+"
"、featuregetter、null);
dogatstatus.append(dogstate);
private ImageGetter featuregetter = new ImageGetter(){
public Drawable getDrawable(String source) {
Log.i(" get drawable mathod ", "");
Bitmap B = BitmapFactory.decodeResource(getResources(),
R.drawable.bone);
BitmapDrawable BD = new BitmapDrawable(B);
BD.setBounds(0, 0, B.getWidth(), B.getHeight());
return BD;
}
};
于 2012-07-23T10:24:56.720 に答える