package com.TestLayout;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class TestLayout extends BaseActivity {
@Override
protected void initRecourse() {
// TODO Auto-generated method stub
}
@Override
protected void initData() {
// TODO Auto-generated method stub
}
@Override
protected ViewGroup initView() {
// 创建LinearLayout对象
LinearLayout mLinearLayout = new LinearLayout(this);
// 建立布局样式宽和高,对应xml布局中:
// android:layout_width="fill_parent"
// android:layout_height="fill_parent"
mLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// 设置方向,对应xml布局中:
// android:orientation="vertical"
mLinearLayout.setOrientation(LinearLayout.VERTICAL);
// 创建TextView对象
TextView mTextView = new TextView(this);
// 设置文字
mTextView.setText("hello world");
// 为其建立布局样式,对应xml布局中:
// android:layout_width="fill_parent"
// android:layout_height="wrap_content"
LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
// 在父类布局中添加它,及布局样式
mLinearLayout.addView(mTextView, mLayoutParams);
return mLinearLayout;
}
}
android编程之代码布局(一)
5星 · 超过95%的资源 需积分: 31 198 浏览量
2012-04-25
17:43:52
上传
评论 5
收藏 13KB RAR 举报
xyz_fly
- 粉丝: 380
- 资源: 16
最新资源
- TG-2024-05-23-204718255.mp4
- 候志强@181 5428 8938_20240420112107.amr
- spispispispispi
- 实验二:IP协议分析.zip
- 驱动代码驱动代码驱动代码驱动代码
- SVID_20240523_141155_1.mp4
- Code for the complete guide to tkinter tutorial
- 关于百货中心供应链管理系统.zip
- SimpleFolderIcon-master 修改Unity的Project下的文件夹图标
- A python Tkinter widget to display tile based maps
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页