继续我之前的帖子,我能够设置多个元素, MultiAutoCompleteTextView但我无法用自定义背景和关闭按钮包装那些项目,就像链接图片一样.
我能够用单个元素做同样的事情,但是对于多个元素,运气不好.
这是我试过的.
//将文本设置为MultiAutoCompleteTextView
private void setTextSample(String contactName) {
final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = (TextView) LayoutInflater.from(this).inflate(R.layout.textview, null);
tv.setText(contactName);
BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(tv);
bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
sb.append(contactName + ",");
sb.setSpan(new ImageSpan(bd), sb.length()-(contactName.length()+1),
sb.length()-1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mMultiAutoCompleteTextView.setText(sb);
}
Run Code Online (Sandbox Code Playgroud)
//用自定义元素换行文本
private static Object convertViewToDrawable(View view) {
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
view.measure(spec, spec);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.translate(-view.getScrollX(), -view.getScrollY());
view.draw(c);
view.setDrawingCacheEnabled(true);
Bitmap cacheBmp = …Run Code Online (Sandbox Code Playgroud) 我正在向我的应用成功添加adMob横幅广告.当横幅出现时,我需要获得其高度以调整所有布局元素的大小.我正在使用事件onReceivedAd,这是正确触发的.但是,alturaBanner = 0.那么,如何获得它的高度?谢谢.
/** Called when an ad is received. */
@Override
public void onReceiveAd(Ad ad)
{
adView.setVisibility(View.VISIBLE);
int alturaBanner = adView.getHeight();
RelativeLayout.LayoutParams params1 = (android.widget.RelativeLayout.LayoutParams) browse2
.getLayoutParams();
params1.setMargins(0, alturaBanner, 0, 0);
Log.d(LOG_TAG, "onReceiveAd");
Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)