代码编写布局

以前没有用代码写个布局文件,今天尝试了下,

很不熟悉,不过总算搞定,做笔记以防忘记!

package com.login.login.widget;

import com.login.login.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner;

public class SpinnerTestActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.spinnertest);

		ScrollView scrollView = new ScrollView(this);

		LinearLayout l = new LinearLayout(this);
		l.setOrientation(LinearLayout.VERTICAL);
		scrollView.addView(l);
		
		int textViewResourceId = android.R.layout.simple_spinner_item;
		creatspinner(textViewResourceId, l);
		int textViewResourceId2 = android.R.layout.browser_link_context_header;
		creatspinner(textViewResourceId2, l);
		int textViewResourceId3 = android.R.layout.preference_category;
		creatspinner(textViewResourceId3, l);
		int textViewResourceId4 = android.R.layout.select_dialog_item;
		creatspinner(textViewResourceId4, l);
		int textViewResourceId5 = android.R.layout.select_dialog_multichoice;
		creatspinner(textViewResourceId5, l);
		int textViewResourceId6 = android.R.layout.select_dialog_singlechoice;
		creatspinner(textViewResourceId6, l);
		int textViewResourceId7 = android.R.layout.simple_dropdown_item_1line;
		creatspinner(textViewResourceId7, l);
		int textViewResourceId8 = android.R.layout.simple_expandable_list_item_1;
		creatspinner(textViewResourceId8, l);
		int textViewResourceId9 = android.R.layout.simple_gallery_item;
		creatspinner(textViewResourceId9, l);
		int textViewResourceId10 = android.R.layout.simple_list_item_1;
		creatspinner(textViewResourceId10, l);
		int textViewResourceId11 = android.R.layout.simple_list_item_checked;
		creatspinner(textViewResourceId11, l);
		int textViewResourceId12 = android.R.layout.simple_list_item_multiple_choice;
		creatspinner(textViewResourceId12, l);
		int textViewResourceId13 = android.R.layout.simple_list_item_single_choice;
		creatspinner(textViewResourceId13, l);
		int textViewResourceId14 = android.R.layout.simple_spinner_dropdown_item;
		creatspinner(textViewResourceId14, l);
		int textViewResourceId15 = android.R.layout.simple_spinner_item;
		creatspinner(textViewResourceId15, l);
		int textViewResourceId16 = android.R.layout.test_list_item;
		creatspinner(textViewResourceId16, l);
		setContentView(scrollView);
	}

	private void creatspinner(int style_layout, LinearLayout l) {
		Spinner sp = new Spinner(this);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, style_layout);

		adapter.add("red");
		adapter.add("green");
		adapter.add("yellow");
		adapter.add("black");
		adapter.add("write");
		adapter.add("blue");

		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		sp.setAdapter(adapter);

		LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		l.addView(sp, ll);
//		setContentView(l);
	}

}













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值