【发布时间】:2015-11-05 07:17:03
【问题描述】:
我需要在选项卡布局中的选项卡中将图像设置在文本上方。所以我使用 setCompoundDrawablesWithIntrinsicBounds 在我的TextView 中设置图像,但我不知道如何为我的图像指定大小。
我试图给出这样的尺寸:
Drawable dr = ContextCompat.getDrawable(MainActivity.this, R.drawable.mobile_icon);
Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
mobile_drawable = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 50, 50, true));
TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabOne.setText("Mobile");
tabOne.setCompoundDrawablesWithIntrinsicBounds(0,mobile_drawable,0,0);
tabLayout.getTabAt(0).setCustomView(tabOne);
但它给了我这个错误:
Cannot resolve method setCompoundDrawablesWithIntrinsicBounds(int,android.graphics.drawable.Drawable,int,int);
我也试过
tabOne.setCompoundDrawables(0,mobile_drawable,0,0);
但它也不起作用?
那么在使用setCompoundDrawablesWithIntrinsicBounds时如何给图片尺寸???
【问题讨论】:
标签: android bitmap android-drawable