我面臨的一個問題是更新TextView
RelativeLayout
中的內容。當我第二次更新時,我需要清除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);
}
任何你沒有使用linearLayout或者ListView的原因? – Nerkatel
所以我可以刪除文本時,我使用linearlayout? – user2342350