我面临一个更新TextView
内容的问题RelativeLayout
。当我第二次更新时,我需要从RelativeLayout
.
RelativeLayout
我的应用中有一个activity_calendar.xml
<RelativeLayout
android:id="@+id/rel_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/linearLayout1"
android:layout_toRightOf="@+id/linearLayout1">
</RelativeLayout>
这是主要代码:
public void listall () {
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.rel_container);
int prevTextViewId = 0;
for (int i = 0; i < titleCalendar.length; i++) {
final TextView textView = new TextView(this);
textView.setText(titleCalendar[i]);
cnvrttime = hourCalendar[i] - 3;
addcnvrtTime = 60*cnvrttime;
curTextViewId = prevTextViewId + 1;
textView.setId(curTextViewId);
final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, addcnvrtTime);
params.setMargins(0, convertDPtoInt((float)addcnvrtTime), 0, 0);
textView.setLayoutParams(params);
prevTextViewId = curTextViewId;
relativeLayout.addView(textView, params);
}