我正在尝试动态地将视图添加到线性布局,但是如果我尝试将两个视图添加到线性布局,则无法显示第二个视图。第二种观点完全是空白的。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textStyle="bold"
android:padding="10dp"
android:background="@color/colorPrimary"
android:text="Leads That Need Action Today"/>
<LinearLayout
android:id="@+id/action_leads_list_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textStyle="bold"
android:padding="10dp"
android:background="@color/colorPrimary"
android:text="Overdue Tasks"/>
<LinearLayout
android:id="@+id/overdue_tasks_list_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
- 通过json数组调用将视图添加到线性布局的函数
JSONArray jsonArray = new JSONArray(rsp);
for(int j = 0; j < jsonArray.length(); j++){
JSONObject jObj = jsonArray.getJSONObject(j);
Lead lead = new Lead();
lead.name = jObj.getString("FirstName") + " " + jObj.getString("LastName");
addViewToLayout(lead);
}
private void addViewToLayout(Lead lead){
View view = mActivity.getLayoutInflater().inflate(R.layout.list_item_today_task, null);
TextView name = (TextView) view.findViewById(R.id.name);
name.setText(lead.name);
actionsListLeadLayout.addView(view);
}