怎样在imagebutton内添加图片和文字?解决方案
怎样在imagebutton内添加图片和文字?
如题:imagebutton好象添加了图片以后就不能显示文字了.
如何画一个既有图片又有文字的imagebutton.
左边为图片,右边为文字,该如何实现.
------解决方案--------------------
可从Linearlayout继承,扩展需要的layout
如题:imagebutton好象添加了图片以后就不能显示文字了.
如何画一个既有图片又有文字的imagebutton.
左边为图片,右边为文字,该如何实现.
------解决方案--------------------
可从Linearlayout继承,扩展需要的layout
- Java code
import 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); } }