android 获取屏幕编号,如何使用edittext,textview和前一屏幕android中给定输入编号的图像创建动态布局?...

尝试这个。根据您的需要定制。

主要活动

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Intent i = new Intent(MainActivity.this,SecondActivity.class);

i.putExtra("VALUE", 2); //Dynamic value

startActivity(i);

}

}SecondActivity

public class SecondActivity extends Activity {

LinearLayout LLMain;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.second);

LLMain = (LinearLayout)findViewById(R.id.Linearroot);

Intent intent = getIntent();

int Value = intent.getIntExtra("VALUE", 0);

for(int i = 0;i < Value;i++)

{

CreateLayout(i);

}

}

public void CreateLayout(int val)

{

LinearLayout LLTop = new LinearLayout(this);

LLTop.setOrientation(LinearLayout.HORIZONTAL);

LinearLayout LLBtm = new LinearLayout(this);

LLBtm.setOrientation(LinearLayout.VERTICAL);

LinearLayout.LayoutParams paramT,paramB,param1,param2,param3,param4,param5,param6;

paramT = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

paramT.setMargins(20, 10, 20, 10);

paramB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

paramB.setMargins(20, 10, 20, 10);

param1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

param2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

param2.gravity = Gravity.CENTER_VERTICAL;

param3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

param4 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

param5 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

param6 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

ImageView iv = new ImageView(this);

iv.setBackgroundResource(R.drawable.ic_launcher);

TextView tv = new TextView(this);

tv.setText("Student" + val);

TextView tv1 = new TextView(this);

tv1.setText("Phone");

TextView tv2 = new TextView(this);

tv2.setText("Email");

EditText et = new EditText(this);

EditText et1 = new EditText(this);

LLTop.addView(iv, param1);

LLTop.addView(tv, param2);

LLBtm.addView(tv1, param3);

LLBtm.addView(et, param4);

LLBtm.addView(tv2,param5);

LLBtm.addView(et1,param6);

LLMain.addView(LLTop, paramT);

LLMain.addView(LLBtm,paramB);

}

}second.xml

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/Linearroot"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".SecondActivity" >

希望能帮助到你。!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值