// //线性布局 LinearLayout mainLinearLayout = (LinearLayout) this.getLayoutInflater() .inflate(R.layout.main, null); setContentView(mainLinearLayout); EditText editText = new EditText(this); editText.setSingleLine(false); editText.setGravity(Gravity.LEFT); editText.setWidth(50); editText.setHeight(50); mainLinearLayout.addView(editText, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); al = new AbsoluteLayout(this); al.setBackgroundColor(Color.YELLOW); // 构造一个 TextView 并设置其 text 和 背景色 tv = new TextView(this); tv.setText("Android is a software stack for mobile devices that includes an operating system, middleware and key applications. "); tv.setBackgroundColor(Color.BLUE); // 用该 View 在父 View 中的 width,height,x,y 作为参数构造一个 AbsoluteLayout.LayoutParams AbsoluteLayout.LayoutParams tvLP = new AbsoluteLayout.LayoutParams(70, 50, 100, 200); // 把这个 TextView 加入到 AbsoluteLayout 中,并应用上一步创建的 LayoutParams。这样 TextView 就会显示在我们指定的位置上了。 tv.setLayoutParams(tvLP); al.addView(tv); this.setContentView(al); |
|