android基础--通过编码实现软件界面
2011-10-18 17:46
507 查看
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);//创建一个线性布局
layout.setOrientation(LinearLayout.VERTICAL);//设置布局的方向
LinearLayout.LayoutParams params
= new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT); //为布局设置参数,长度宽度填充父元素
LinearLayout.LayoutParams params2
= new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);//为布局设置参数,长度宽度填充父元素
TextView textView = new TextView(this);
textView.setText(R.string.hello);
layout.addView(textView,params2);
//上面是通过代码实现界面,下面代码时通过xml文件生成界面
LayoutInflater inflater
= (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); //布局填充服务
View view = inflater.inflate(R.layout.part, null);//用part.xml生成一个view对象
layout.addView(view);
setContentView(layout,params);
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);//创建一个线性布局
layout.setOrientation(LinearLayout.VERTICAL);//设置布局的方向
LinearLayout.LayoutParams params
= new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT); //为布局设置参数,长度宽度填充父元素
LinearLayout.LayoutParams params2
= new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);//为布局设置参数,长度宽度填充父元素
TextView textView = new TextView(this);
textView.setText(R.string.hello);
layout.addView(textView,params2);
//上面是通过代码实现界面,下面代码时通过xml文件生成界面
LayoutInflater inflater
= (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); //布局填充服务
View view = inflater.inflate(R.layout.part, null);//用part.xml生成一个view对象
layout.addView(view);
setContentView(layout,params);
}
}
相关文章推荐
- android编码实现软件界面
- android 程式开发:(十)绘制用户界面 —— 10.1通过纯编码实现UI
- Android编码实现软件界面
- Android应用开发之编码实现 软件界面
- Android成长之路-编码实现软件界面
- android基础--采用HTML实现软件界面
- Android编码实现软件界面
- 23、Android开发基础之通过隐式意图来实现界面的跳转
- Android成长之路-编码实现软件界面
- Android中编码实现软件界面
- Android中通过样式来去除app的头及界面全屏(备忘)的实现方法
- 【Android】Glide 实现图片再处理(比如在右下角添加 GIF 标识、圆角处理、添加水印等,通过在原 bitmap 的基础上进行再处理)
- Android Toast优化--通过自定义布局实现界面美化
- Android基础:代码中实现界面动态布局
- Android 基础:SharePreferences知识总结和在“登录”界面的范例实现
- Android通过ViewPager实现引导界面(一)
- Android 实现H264编码,解码。并通过WiFi传输实现视频监控。
- Android通过SharedPreferences实现记住密码的登陆界面
- android基础---简易闪屏操作,通过动画实现
- Android通过自定义控件实现360软件详情页效果