重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

android动态添加,android动态添加小工具

动态添加Android(安卓)控件?

先定义出想要的控件,给这个控件里填加相应的属性,然后定义一个布局,把控件添加到布局里面,再把这个布局导入到界面里,代码如下:

我们提供的服务有:网站制作、成都网站建设、微信公众号开发、网站优化、网站认证、八公山ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的八公山网站制作公司

RelativeLayout.LayoutParams

layoutParams

=

new

RelativeLayout.LayoutParams(100,

100);

layoutParams.topMargin=8;

layoutParams.leftMargin=8;

layoutParams.rightMargin=8;

layoutParams.bottomMargin=8;

insertLayout.addView(imgApple2,layoutParams);

Android gradle 动态添加模块依赖

Android 开发过程,可能会遇到依赖模块太多,手动的添加修改依赖就会觉得有点麻烦,这个时候可以考虑使用动态添加模块依赖,也是适用像 Jenkins 自动打包构建,就不需要频繁的去修改模块依赖,提高构建效率。

1、工程 settings.gradle 动态添加模块工程

2、 app 模块 build.gradle 依赖使用

Gradle dependencies: compile project by relative path

Android studio add external project to build.gradle

android 动态添加控件 怎么刷新页面

1、动态添加的时候为组件设置id,删除的时候根据id查找到对应组件,然后删除

2、根据父节点,获取所有父组件下的子组件,然后依次删除。

示例:

protected View createView() {//动态添加组件

Button btn = new Button(this);//动态创建按钮

btn.setId(index++);

btn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

btn.setText("aaaaaa" + index);

return btn;

}

private void removeView() {//动态删除组件(按钮)

//获取linearlayout子view的个数

int count = linearLayout.getChildCount();

//研究整个LAYOUT布局,第0位的是含add和remove两个button的layout

//第count-1个是那个文字被置中的textview

//因此,在remove的时候,只能操作的是0locationcount-1这个范围的

//在执行每次remove时,我们从count-2的位置即textview上面的那个控件开始删除~

if (count - 2 0) {

//count-20用来判断当前linearlayout子view数多于2个,即还有我们点add增加的button

linearLayout.removeViewAt(count - 2);

}

}

android中如何动态创建数据表

在布局中加入表格

TableLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/table1"

/TableLayout

之后再 MainActivity 中写入动态添加的代码

public void click(View v) {

if(row.getText().length()0column.getText().length()0){

//把输入的行和列转为整形

int row_int=Integer.parseInt(row.getText().toString());

int col_int=Integer.parseInt(column.getText().toString());

//获取控件tableLayout

tableLayout = (TableLayout)findViewById(R.id.table1);

//清除表格所有行

tableLayout.removeAllViews();

//全部列自动填充空白处

tableLayout.setStretchAllColumns(true);

//生成X行,Y列的表格

for(int i=1;i=row_int;i++)

{

TableRow tableRow=new TableRow(MainActivity.this);

for(int j=1;j=col_int;j++)

{

//tv用于显示

TextView tv=new TextView(MainActivity.this);

//Button bt=new Button(MainActivity.this);

tv.setText("("+i+","+j+")");

tableRow.addView(tv);

}

//新建的TableRow添加到TableLayout

tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC,1));

}

}else{

Toast.makeText(MainActivity.this,"请输入数值",1).show();

}

}

android动态添加布局时,布局参数不生效

增加父类布局,即要添加到的布局,如下:

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

RelativeLayout rl = (RelativeLayout)findViewById(R.id.rl);

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(

LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

params.width = 200;

params.height = 200;

params.topMargin = 200;

params.leftMargin = 200;

ImageView view = new ImageView(getApplicationContext());

view.setBackgroundResource(R.drawable.ic_launcher);

rl.addView(view, params);

}

android 如何实现动态添加布局

如下代码:

LinearLayout layout = new LinearLayout(this);

TextView tx = new TextView(this);

tx.setText('我是动态添加的');

layout.addView(tx);

setContentView(layout);

这就动态添加了一个线性布局,并且在布局里面加了一个textview


本文题目:android动态添加,android动态添加小工具
标题网址:http://cqcxhl.com/article/dscojod.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP