安卓:充气的XML文件的特定部分 [英] Android: Inflating a specific section of an xml file

查看:91
本文介绍了安卓:充气的XML文件的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要夸大低于code(从Android API演示list_item_icon_text.xml拍摄)。

I wish to inflate the code below (taken from list_item_icon_text.xml of the android api demos).

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView android:id="@+id/icon"
        android:layout_width="48dip"
        android:layout_height="48dip" />

    <TextView android:id="@+id/text"
        android:layout_gravity="center_vertical"
        android:layout_width="0dip"
        android:layout_weight="1.0"
        android:layout_height="wrap_content" />

</LinearLayout>

不幸的是,在演示中,通货膨胀是用做

Unfortunately, in the demo, the inflation was done using

convertView = mInflater.inflate(R.layout.list_item_icon_text, null);

在list14.java。

in list14.java.

我想包括我自己的xml文件上面code和充气仅此的LinearLayout ,但我一直在网上进行搜索并尝试了几个小时做到这一点。我真的很沮丧在这一点上。我设法抬高整个xml文件,这不是我想要的东西。我只是想夸大这一特定部分(有它添加到我的XML文件)。任何帮助是极大的AP preciated。

I would like to include the above code in my own xml file and only inflate this LinearLayout, but I have been searching online and trying to do this for hours. I'm really frustrated at this point. I managed to inflate the whole xml file, which is not what I wanted. I only want to inflate this particular section (having added it to my xml file). Any help is greatly appreciated.

推荐答案

您只好将文件保存在你的布局文件夹,让我们说'my_layout.xml `和膨胀,你会用你的ID时:

You'll just have to save your file in your layout folder, let say 'my_layout.xml` and when inflating you'll use your id :

     inflate(R.layout.my_layout);

要确保正确进口的。我的意思是通过导入您的 R.java 文件:

     import my.packaage.com.R;

这篇关于安卓:充气的XML文件的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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