我需要将图片设置在选项卡中的文字上方,因此我使用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时如何指定图像大小呢?