【Android】使用代码动态创建布局
16lz
2021-12-04
package com.android.myfirstandroidapp;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;import android.widget.LinearLayout;public class MyFirstAndroidAppActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 使用代码动态布局界面的例子 TextView text1 = new TextView(this); text1.setText("Hi there!"); TextView text2 = new TextView(this); text2.setText("I'm seconed. I need to wrap."); text2.setTextSize( (float)60 ); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(text1); ll.addView(text2); setContentView(ll); }}
更多相关文章
- android代码混淆后gson无法解析问题
- Android(安卓)anr异常测试
- Android(安卓)界面的横竖屏监听
- Android(安卓)SDK 源代码编译
- Android简单计算器界面实现
- 获取Android设备IMEI
- android的单选框例子
- android 混编源代码
- Android(安卓)ProgressBar简单使用