Android 在LinearLayout视图中遍历所有子对象时获取ClassCastException?

Android 在LinearLayout视图中遍历所有子对象时获取ClassCastException?,android,Android,我希望在线性布局中遍历所有视图,但在最后一个元素,在框架布局中,以及它的正确类中,我得到了一个例外 public void traverseRootsViewAndSetLayoutParam(View view, double heightRatio, double widthRatio) { view.setLayoutParams(new LinearLayout.LayoutParams( (int) (((double) widthRat

我希望在线性布局中遍历所有视图,但在最后一个元素,在框架布局中,以及它的正确类中,我得到了一个例外

public void traverseRootsViewAndSetLayoutParam(View view,
        double heightRatio, double widthRatio) {
    view.setLayoutParams(new LinearLayout.LayoutParams(
            (int) (((double) widthRatio) * (view.getWidth())),
            (int) (((double) heightRatio) * (view.getHeight()))));
    if (view instanceof LinearLayout || view instanceof FrameLayout) {
        if (view instanceof LinearLayout) {
            System.out.println(">>> LinearLayout Class >>> "
                    + view.getClass());
            int childcount = ((LinearLayout) view).getChildCount();
            for (int i = 0; i < childcount; i++) {
                View childView = ((LinearLayout) view).getChildAt(i);
                traverseRootViewAndSetLayoutParam(childView, heightRatio,
                        widthRatio);
            }
        } else if (view instanceof FrameLayout) {
            System.out.println(">>> FrameLayout Class >>> "
                    + view.getClass());
            // getting error here , even the view is framelayout???
            int childcount = ((FrameLayout) view).getChildCount();
            for (int i = 0; i < childcount; i++) {
                View childView = ((FrameLayout) view).getChildAt(i);
                traverseRootViewAndSetLayoutParam(childView, heightRatio,
                        widthRatio);
            }
        }
    }
}
public void transverserootsviewandsetlayoutparam(视图,
双高比、双宽比){
view.setLayoutParams(新的LinearLayout.LayoutParams(
(int)(((双)宽度比)*(view.getWidth()),
(int)((双)高度比)*(view.getHeight());
if(线性布局的视图实例| |框架布局的视图实例){
if(查看LinearLayout的实例){
System.out.println(“>>>线性布局类>>>”
+view.getClass());
int childcount=((LinearLayout)视图).getChildCount();
for(int i=0;i>>框架布局类>>>”
+view.getClass());
//在这里获取错误,即使视图是framelayout???
int childcount=((FrameLayout)视图);
for(int i=0;i
框架布局中的子视图是什么?递归处理所有子视图节点?那代码没用。