简体   繁体   English

Android复合绘图

[英]Android compound drawable

I am using a custom toast, with a ImageView and a TextView using a background in drawable. 我正在使用自定义吐司,使用ImageViewTextView使用可绘制背景。 But the Android Studio tells me to use a single TextView and a compound drawable instead. 但是Android Studio告诉我使用单个TextView复合可绘制对象 I have already used a drawable for background, but how can I "draw" a picture at a certain position relative to the TextView ? 我已经使用了drawable作为背景,但是如何在相对于TextView的某个位置“绘制”图片?

You can use a single TextView and a CompoundDrawable like this 您可以像这样使用单个TextViewCompoundDrawable

Toast toast = Toast.makeText(this, "Custom Compount Drawable Toast", Toast.LENGTH_LONG);
View toastView = toast.getView(); //This'll return the default View of the Toast.

TextView toastMessage = (TextView) toastView.findViewById(android.R.id.textview);
toastMessage.setTextSize(25);
toastMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.image_id, 0, 0, 0);
toastMessage.setGravity(Gravity.CENTER);
toastMessage.setCompoundDrawablePadding(16);
toastView.setBackgroundColor(Color.CYAN);
toast.show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM