添加 imageview 两种方式

package com.zj;

import android.app.Activity;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.os.Bundle;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

public class TestTestActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        

        setContentView(R.layout.main);

        LinearLayout lineLayout = (LinearLayout)findViewById(R.id.main_layout);

        ImageView imageView = new ImageView(this);

        

//      imageView.setBackgroundResource(R.drawable.icon);//形式一setBackgroundResource

        Bitmap sourcePicture = BitmapFactory.decodeResource(getResources(), R.drawable.icon);//形式二得到图片

        imageView.setImageBitmap(sourcePicture);

        

        lineLayout.addView(imageView);

        

    }

}

你可能感兴趣的:(imageview)