如何查看充气从XML在Android中? [英] How to Inflate view from XML in Android?

查看:99
本文介绍了如何查看充气从XML在Android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个tableLayout [XML中给出]

添加表行[在XML中创建和充气用Java]

也增加了2 TextView的表行[XML格式创建,并在充气JAVA]

我能够得到的只有背景和textcolors但不喜欢宽度,高度和利润率来获得表视图的布局属性。

解决方案
  1. 首先声明的充气。

      LayoutInflater吹气=(LayoutInflater)getApplicationContext()。getSystemService
      (Context.LAYOUT_INFLATER_SERVICE);
     

  2. 确定并抬高你寻求项目当前视图的新视图。

     查看视图= inflater.inflate(R.layout.new_layout,NULL);
     

  3. 您会希望您的新充气视图添加到您的布局。

      main.addView(视图);
     

您可以参考这里附加信息:<一href="http://developer.android.com/reference/android/view/LayoutInflater.html">http://developer.android.com/reference/android/view/LayoutInflater.html

I'm creating a tableLayout [given in XML]

adding table Row [created in XML and inflating in Java]

also adding 2 textview to the table Row [created in XML and inflating in JAVA]

I'm able to get only the background and textcolors but not the layout properties like width, height and margin to get table view.

解决方案

  1. First declare your inflater.

    LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService
      (Context.LAYOUT_INFLATER_SERVICE);
    

  2. Identify and inflate the new view you seek to project on the current view.

    View view = inflater.inflate(R.layout.new_layout,null);
    

  3. You would want to add your new inflated view to your layout.

    main.addView(view);
    

You can reference additional information here: http://developer.android.com/reference/android/view/LayoutInflater.html

这篇关于如何查看充气从XML在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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