Android中在Button文本上添加图片

具体效果如下:
Android中在Button文本上添加图片_第1张图片
第一种:
在ImageView标签中添加drawableTop属性添加图片
第二种:
通过监听器完成。

public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        //获得pic数据
        if(convertView == null){
            convertView = mInflater.inflate(mResource, null);
        }
        Pic p = mObjects.get(position);
        //获得图片显示框和文字显示框
        TextView tv_grid = (TextView) convertView.findViewById(R.id.tv_grid);
        //设置内容
        //   获得图片资源
        Drawable top  = mContext.getResources().getDrawable(p.getImgId());
        //   设置图片的边界
        top.setBounds(0, 0, 100, 100);;
        //   将图片设置在textview的top
        tv_grid.setCompoundDrawables(null, top, null, null);
        tv_grid.setText(p.getName());
        return convertView;
    }

你可能感兴趣的:(android)