xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/top_tv"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#ffffff"
android:gravity="center"
android:text="在代码中动态布局"
android:textColor="#7B68EE" />
android:id="@+id/child_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_tv"
android:orientation="vertical" >
--------------------------------------------------------------
public class TestActivity extends Activity implements OnClickListener {
private LinearLayout childLinLayout;
private List
tv2.setWidth(width1);
tv2.setHeight(height);
tv2.setBackgroundResource(colors[4]);
}
layout1.addView(tv1);
layout1.addView(tv2);
childLinLayout.addView(layout1);
}
}
/**添加文字数据*/
private void getListData() {
for (int i = 0; i < 6; i++) {
Map strMap = new HashMap();
strMap.put("left", "这是左侧数据" + (i + 1) + "left");
strMap.put("right", "这是右侧数据" + (i + 1) + "right");
viewList.add(strMap);
}
}
@Override
public void onClick(View v) {
TextView tv = (TextView) findViewById(v.getId());
String content = tv.getText().toString();
switch (v.getId()) {
case 1:
showToastMsg(content);
break;
case 2:
showToastMsg(content);
break;
case 3:
showToastMsg(content);
break;
case 4:
showToastMsg(content);
break;
case 5:
showToastMsg(content);
break;
case 6:
showToastMsg(content);
break;
case 7:
showToastMsg(content);
break;
case 8:
showToastMsg(content);
break;
case 9:
showToastMsg(content);
break;
case 10:
showToastMsg(content);
break;
case 11:
showToastMsg(content);
break;
case 12:
showToastMsg(content);
break;
}
}
private void showToastMsg(String content) {
Toast.makeText(TestActivity.this, content + content, Toast.LENGTH_SHORT).show();
}
}
--------res/values/colors.xml-----------------------------
#F0F0F0
#D0D0D0
#EC182E
#C41e85
#8B008B