定义界面布局TextView&Button
2014-04-20 21:45
585 查看
MainActivity.java:
效果:
package com.example.layout; import android.os.Bundle; import android.app.ActionBar.LayoutParams; import android.app.Activity; import android.text.Layout; import android.view.Menu; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView text1 = new TextView(MainActivity.this); text1.setText("zhengzhixiong"); LinearLayout layout = new LinearLayout(MainActivity.this); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); // Button btn3 = new Button(getApplicationContext()); // btn3.setText("Button3"); Button btn1 = new Button(getApplication()); btn1.setText("Button1"); Button btn2 = new Button(getBaseContext()); btn2.setText("Button2"); Button btn3 = new Button(this); btn3.setText("Button3"); // Button btn4 = new Button(getParent()); //不能运行 // btn4.setText("Button4"); //不能运行 layout.addView(text1,p); // layout.addView(btn3); //不能运行 layout.addView(btn1); layout.addView(btn2); layout.addView(btn3); // layout.addView(btn4); //不能运行 // layout.addView(btn5); //不能运行 this.setContentView(layout); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
效果:
相关文章推荐
- 父布局为RelativeLayout,textview设置layout_gravity="center_vertical"无效。
- Android学习笔记-EditText&TextView&Button&菜单栏
- (多码伤眼,伤身,伤脑,勿入)代码写界面(3*label,2*textFIeld,1*slider,2*UISwitch,1*segmentedController,1*button,1*AlertSheet,1*AlertView)
- 自己定义ViewGroup控件(二)----->流式布局进阶(二)
- Android学习笔记-EditText&TextView&Button&菜单栏
- Android-ToggleButton&CheckTextView&CheckBox
- android This tag and its children can be replaced by one <TextView/> and a compound drawable 布局文件提示
- 自己定义ViewGroup控件(二)----->流式布局进阶(二)
- Android实战简易教程<三十二>(自定义View登录注册界面EditText-实现一键清空)
- Android入门笔记 - 界面开发 - TextView,Button,EditText,Toast
- Android - VGA,ADB,DDMS,安卓开发环境目录结构,安卓目录结构,常见布局,点击事件的几种写法,控件(Button/TextView/ImageView/EditText)
- 自己定义ViewGroup控件(一)----->流式布局进阶(一)
- [Multi]AutoCompleteTextView&Button
- CheckedTextView,CheckBox和Button样式定义
- 基本界面组件~TextView~EditText~Button
- 使用DrawerLayout实现侧滑菜单,,RadioButton+Fragment实现页面主布局,首页面使用tabLayout+viewPager实现
- LinearLayout中两个textview布局对齐
- android Button,textView 等控件设置控件内嵌周围图片使用方法
- Android的xml布局文件代码讲解(TextView控件)