获得视图布局 [英] Get layout from view

查看:111
本文介绍了获得视图布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从XML使用充气接口

I am inflating interface from XML using

View add_phone = getLayoutInflater().inflate(R.layout.phone_info, null);

现在如何从add_phone视图访问RelativeLayout的?有没有像 getChildCount任何methos()

Now how can i access RelativeLayout from add_phone view? is there any methos like getChildCount() ?

推荐答案

是的,getChildCount(),工作在一个ViewGroup中像的LinearLayout,RelativeLayout的等。

yes , getChildCount(), works on a ViewGroup like LinearLayout, RelativeLayout etc..

ViewGroup add_phone = (ViewGroup) getLayoutInflater().inflate(R.layout.phone_info, null);
int childCount = add_phone.getChildCount();

您必须确保膨胀的布局有作为的ViewGroup父视图,否则你将得到类转换异常。 ViewGroup中可以像任何的LinearLayout,RelativeLayout的等。

you must make sure the inflated layout has viewGroup as parent view, otherwise you will get class cast exception. viewGroup can be anything like LinearLayout, RelativeLayout etc..

这篇关于获得视图布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆