我试图以LinearLayout编程方式(在循环中)将两个文本视图添加到 a 中,然后依次将其添加到LinearLayout布局文件中定义的 a 中。代码运行时没有错误,并且在评估 getChildCount 时我得到了预期值,但设备上绝对没有渲染任何内容。
XML:
<LinearLayout
android:id="@+id/llNotes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="@dimen/activity_vertical_margin_quarter"
android:background="@drawable/rounded_bottom_corners"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin_half"
android:paddingBottom="@dimen/activity_vertical_margin" />
爪哇:
for (Note MyNote : foo.GetNotes()) {
LinearLayout llNoteParent = new LinearLayout(this);
TextView tvNoteHeader = new TextView(this);
TextView tvNoteValue = new TextView(this);
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llParams.gravity = Gravity.CENTER_HORIZONTAL;
llNoteParent.setLayoutParams(llParams);
llNoteParent.setOrientation(LinearLayout.HORIZONTAL);
llNoteParent.setBackgroundColor(ContextCompat.getColor(this, R.color.white));
llNoteParent.setPadding(R.dimen.activity_horizontal_margin, R.dimen.activity_vertical_margin_half, R.dimen.activity_horizontal_margin, R.dimen.activity_horizontal_margin);
}
一只萌萌小番薯
慕容3067478
相关分类