构造一个3行4列的“QQ相册列表”

运行效果:


image.png

xml代码






主函数代码

public class QQPicture extends AppCompatActivity {
private ImageView[] img=new ImageView[12];
private int[] imagePath = new int[]{
        R.mipmap.p1,R.mipmap.p2,R.mipmap.p3,R.mipmap.p4,R.mipmap.p5,R.mipmap.p6
};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qqpicture);
        GridLayout layout=(GridLayout)findViewById(R.id.layout);
        for (int i = 0; i < imagePath.length; i++) {
            img[i]=new ImageView(QQPicture.this);
            img[i].setImageResource(imagePath[i]);
            img[i].setPadding(2,2,2,2);
            ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(116,68);
            img[i].setLayoutParams(params);
            layout.addView(img[i]);

        }
    }
}

你可能感兴趣的:(构造一个3行4列的“QQ相册列表”)