码迷,mamicode.com
首页 > 移动开发 > 详细

Android Studio开发基础之使用XML和Java代码混合控制UI界面

时间:2015-05-19 16:36:20      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="@drawable/bg"
    android:id="@+id/layout">
</LinearLayout>

package com.example.lhb.contentprovider1;

import android.app.ActionBar;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Color;
import android.provider.ContactsContract;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LinearLayout LL=(LinearLayout)findViewById(R.id.layout);

        ImageView []Img=new ImageView[4];
        int []ImgSource=new int[]{
             R.drawable.pic1,R.drawable.pic2,R.drawable.pic3,R.drawable.pic4
        };

        for(int i=0;i<ImgSource.length;i++){
            Img[i]=new ImageView(this);
            Img[i].setImageResource(ImgSource[i]);
            Img[i].setPadding(4,4,4,4);
            ViewGroup.LayoutParams LP=new ViewGroup.LayoutParams(200,150);
            Img[i].setLayoutParams(LP);
            LL.addView(Img[i]);
        }
    }
}


Android Studio开发基础之使用XML和Java代码混合控制UI界面

标签:

原文地址:http://blog.csdn.net/lucky51222/article/details/45845571

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!