Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 让所有的孩子都排成直线_Java_Android_Android Layout_Android Linearlayout_Programmatically Created - Fatal编程技术网

Java 让所有的孩子都排成直线

Java 让所有的孩子都排成直线,java,android,android-layout,android-linearlayout,programmatically-created,Java,Android,Android Layout,Android Linearlayout,Programmatically Created,如何让所有的孩子在以后使用它们 LinearLayout createRow(LinearLayout parrent, int id, int orientation, int color){ LinearLayout cell = new LinearLayout(this); LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams( LinearLayout.Layout

如何让所有的孩子在以后使用它们

LinearLayout createRow(LinearLayout parrent, int id, int orientation, int color){
    LinearLayout cell = new LinearLayout(this);
    LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    rowParams.weight = 1;
    rowParams.setMargins(5,2,5,2);

    cell.setLayoutParams(rowParams);

    cell.setBackgroundColor(color);
    cell.setOrientation(orientation);
    cell.setId(id);

    parrent.addView(cell);

    cell.setOnClickListener(cellListener);
    return cell;
}

您可以使用
getChildCount()
一旦你有了它,你可以像这样循环:

int childCount = cell.getChildCount();
View child;
for(int i=0; i++; i<childCount)
{
   child = cell.getChildAt(i);
   // do what you want with each child element
}
int childCount=cell.getChildCount();
看孩子;
对于(int i=0;i++;i