问题
I have to create the Layout (in xml or in java) as like Below image :

But it should be repeated as per the Condition. Suppose, if the Arraylist.size() is more then 2 then the whole layout should be repeated as such time. is it possible?
if yes then let me know how it is possible.
I want to create such layout in verticle direction of the linear layout.
Thanks.
Edited: with jin35 answer i have done like this:
private void doCalculationForMultipleEmployee() {
singleEmployee.setVisibility(View.GONE);
for (int i = 0; i<=tempEmployerList.size()-1; i++) {
View repeatedLayout = LayoutInflater.from(getApplicationContext()).inflate(R.layout.test);
((TextView)repeatedLayout.findViewById(R.id.list_title)).setText("Employee"+i);
// customize repeatedLayout with other data
myLinearLayout.addChild(repeatedLayout);
}
}
But i got syntex error at .inflate and at .addChild Please help me for that. Whats wrong with that ?
回答1:
You should create xml file with LinearLayout
and another xml with you "repeating" layout. Then in code for every part of data just use this:
for (Employee e : employeeList) {
View repeatedLayout = LayoutInflater.from(context).inflate(R.your_repeated_layout);
((TextView)repeatedLayout.findViewById(R.id.employee_salary)).setText(e.getSalary())
// customize repeatedLayout with other data
yourLinearLayout.addChild(repeatedLayout);
}
回答2:
why dont you try scroll view and embedd image and text view inside and link onCreate() using views methods (Layout onMeasure) : http://developer.android.com/reference/android/view/View.html
来源:https://stackoverflow.com/questions/8815105/android-repeatedly-create-such-xml-layout-in-android