Android控件之Button图片文字的混排

android:drawableTop="@drawable/img1";上下左右在xml中控制

 

=============================================================

  show = (Button) findViewById(R.id.show);
  
  
  // 在Android中显示图片信息,必须使用Bitmap
  Bitmap bitmapL = BitmapFactory.decodeResource(getResources(),
    R.drawable.img1);

  ImageSpan imageSpanL = new ImageSpan(bitmapL,DynamicDrawableSpan.ALIGN_BOTTOM);

  SpannableString ssL = new SpannableString("img");

  ssL.setSpan(imageSpanL, 0, 3,
    SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
  
  Bitmap bitmapR = BitmapFactory.decodeResource(getResources(),
    R.drawable.img1);

  ImageSpan imageSpanR = new ImageSpan( bitmapR,DynamicDrawableSpan.ALIGN_BOTTOM);

  SpannableString ssR = new SpannableString("img");

  ssR.setSpan(imageSpanR, 0, 3,
    SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
  
  show.append(ssL);
  show.append("zhongjian");
  show.append(ssR);

 

你可能感兴趣的:(Android,UI控件)