MainActivity例如下列:

package cc.testcompounddrawables;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.TextView;
/**
 * Demo描写叙述:
 * 測试getCompoundDrawables()方法.
 * Returns drawables for the left, top, right, and bottom borders.
 * 该方法返回包括控件左,上,右,下四个位置的Drawable的数组
 */
public class MainActivity extends Activity {
    private TextView mTextView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		init();
	}
    private void init(){
    	mTextView=(TextView) findViewById(R.id.textView);
    	Drawable [] drawables=mTextView.getCompoundDrawables();
    	for (int i = 0; i < drawables.length; i++) {
    		Drawable drawable=drawables[i];
    		System.out.println("第"+i+"张图片 width="+drawable.getBounds().width()+
    				           ",height="+drawable.getBounds().height());
		}
    }
	

}


main.xml例如以下:


版权声明:本文博主原创文章,博客,未经同意不得转载。

相关文章:

  • 2022-02-02
  • 2022-12-23
  • 2021-08-10
  • 2021-05-27
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2021-07-18
  • 2021-10-22
  • 2022-12-23
  • 2021-10-03
  • 2021-08-04
  • 2022-02-07
相关资源
相似解决方案