如何获得膨胀的ViewGroup布局的Andr​​oid之后? [英] How to get ViewGroup after inflate layout in Android?

查看:129
本文介绍了如何获得膨胀的ViewGroup布局的Andr​​oid之后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的我的自定义视图布局:

I have layout with my custom view like this :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView1"
    android:layout_marginLeft="30dp"
    android:layout_toRightOf="@+id/imageView1"
    android:text="Username"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textStyle="bold" />

.....

然后我想从这个XML文件得到的ViewGroup。但是,我知道的方式,只是用充气吹气查看这样的布局 LayoutInflater.inflate(R.id.my_layout)和回报仅仅是查看键,我的布局是绝对 RelativeLayout的扩展的ViewGroup

And then I want to get ViewGroup from this xml files. But the manner that I know is just inflate the layout with View Inflater like this LayoutInflater.inflate(R.id.my_layout) and the return is just View And my layout is absolutely RelativeLayout that extends ViewGroup.

我怎样才能得到我的RelativeLayout为的ViewGroup编程?

How can I get My Relativelayout as ViewGroup programmatically?

推荐答案

充气类型转换入相对布局后。在每一个Android的布局图,该超类的所有意见和viewgroups ..

After inflating typecast it into relative layout. In android every layout is view which is super class of all views and viewgroups..

您必须强制转换这样的..

you have to typecast like this..

convertView = inflater.inflate(R.layout.header, null);
RelativeLayout lyLayout=(RelativeLayout) convertView;

这篇关于如何获得膨胀的ViewGroup布局的Andr​​oid之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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