如题:imagebutton好象添加了图片以后就不能显示文字了.
如何画一个既有图片又有文字的imagebutton.
左边为图片,右边为文字,该如何实现.

解决方案 »

  1.   

    那么楼主为什么不用button呢,直接背景为图片,然后设置文字不行嘛?
      

  2.   

    可从Linearlayout继承,扩展需要的layoutimport android.widget.LinearLayout;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.ImageView;
    import android.widget.TextView;
     
    public class ImageButton1 extends LinearLayout
    {
      private ImageView mImage;
      private TextView mText;
     
      public ImageButton1(Context context, AttributeSet attrs)
      {
        super(context,attrs);
     
        mImage = new ImageView(context,attrs);
        mImage.setPadding(0,0,0,0);
        mText = new TextView(context,attrs);
        mText.setGravity(android.view.Gravity.CENTER_HORIZONTAL);
        mText.setPadding(0,0,0,0);
     
        setClickable(true);
        setFocusable(true);
        setBackgroundResource(android.R.drawable.btn_default);
        setOrientation(LinearLayout.HORIZONTAL);
        addView(mImage);
        addView(mText);
      } 
    }
    使用时,和正常的button一样,可设置OnClickListener等。显示出来后左图右文字,当然可以自己调整。
      

  3.   

    学习下~正想弄个相似的ImageButton