如何获得RelativeLayout的合作与合并,包括? [英] How to get RelativeLayout working with merge and include?

查看:105
本文介绍了如何获得RelativeLayout的合作与合并,包括?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力,现在几天通过使用几个层次的转换,使我的布局更有效的嵌套 LinearLayouts 来一个 RelativeLayout的和所遇到的,我的天堂没有能够找到一个解决方法......几个问题。

I have been trying for a few days now to make my layouts more efficient by converting from using several levels of nested LinearLayouts to one RelativeLayout and have come across a few problems that I haven not been able to find a workaround for...

我已经搜索了Android初学者组,本网站一直没能找到任何可以帮助我解决了问题。

I have searched the Android beginners group and this site and have not been able to find anything that would help me solve the problem.

我读的,你可以结合的布局与合并,包括标签的博客之一。因此,我拥有的是一个 RelativeLayout的根元素主要布局文件。里面的,我有5包含引用各有一个合并元素的5根不同的XML布局文件标签(我所有的合并文件,除了在他们的ID相同)。

I read on one of the blogs that you can combine layouts with merge and include tags. So what I have is a main layout file with a RelativeLayout root element. Inside of that I have 5 include tags that reference 5 different xml layout files that each have a merge element for the root (all of my merge files are the same except for the ids in them).

我遇到了两个问题,我会张贴我的布局code的简化版本后解释:

I am running into two problems, which I will explain after posting a simplified version of my layout code:

样品主要布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/translucent_gray" >

    <include 
        android:id="@+id/running_gallery_layout_id"
        layout="@layout/running_gallery_layout" />

    <include 
        android:id="@+id/recent_gallery_layout_id" 
        layout="@layout/recent_gallery_layout"
        android:layout_below="@id/running_gallery_layout_id" />

    <include
        android:id="@+id/service_gallery_layout_id"
        layout="@layout/service_gallery_layout"
        android:layout_below="@id/recent_gallery_layout_id" />

    <include
        android:id="@+id/process_gallery_layout_id"
        layout="@layout/process_gallery_layout"
        android:layout_below="@id/service_gallery_layout_id" />

</RelativeLayout>

样本包括合并文件:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView 
        style="@style/TitleText"
        android:id="@+id/service_gallery_title_text_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="@string/service_title" />

    <Gallery
        android:id="@+id/service_gallery_id"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_below="@id/service_gallery_title_text_id" />

    <TextView 
        style="@style/SubTitleText"
        android:id="@+id/service_gallery_current_text_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/service_gallery_title_text_id"
        android:layout_above="@id/service_gallery_id" />
</merge>

我遇到了两个问题:

I am running into two problems:

1)安卓布局_ * 属性似乎被忽略了包括标签使用,所有合并的布局都显示在彼此之上时。根据这个帖子(<一href="http://developer.android.com/resources/articles/layout-tricks-reuse.html">http://developer.android.com/resources/articles/layout-tricks-reuse.html) 任何安卓;有/&GT;布局_ * 属性可以用中所使用标记

1) The android:layout_* attributes seem to be ignored when used in the include tag and all of the merged layouts are displayed on top of each other. According to this post (http://developer.android.com/resources/articles/layout-tricks-reuse.html) "any android:layout_* attribute can be used with the <include /> tag"

2)因为我无法得到这个工作,我决定尝试添加安卓layout_below 属性的第一个的TextView 中的每个合并布局文件的项目,这意味着每一个合并的文件将被引用从另一个合并的布局文件的ID ......在大多数情况下这种实际工作和我的布局看起来不错。不过,我得到一个错误上的安卓之一:layout_below 属性说,它无法找到我指定的...我有双重和三重检查IDS的id确保它们是正确的。最奇怪的是,我使用了自动填充功能把ID在属性摆在首位。

2) Since I couldn't get this working I decided to try adding an android:layout_below attribute to the first TextView item in each merge layout file, meaning that each merge file would be referencing an id from another merge layout file... For the most part this actually worked and my layout looks fine. However, I get an error on one of the android:layout_below attributes saying that it can't find the id I specified... I have double and triple checked the ids to make sure they were correct. The weirdest part is that I used the AutoFill feature to put the id in the attribute in the first place.

如果任何人有任何建议或解决方法我会更乐意尝试一下。此外,如果任何人都可以想出一个办法,我只是有一个合并XML布局文件,而不是5,这将是极大的AP preciated。我无法找到一个方法来做到这一点,因为我需要在运行时访问每个项目在合并布局文件...

If anyone has any suggestions or workarounds I will be more than happy to try them out. Also, if anyone can think of a way for me to just have one merge xml layout file instead of 5 that would be greatly appreciated. I couldn't find a way to do that because I need to have access to each item in the merge layout files at runtime...

在此先感谢!

推荐答案

有一个问题,包括标签。检查:<一href="http://$c$c.google.com/p/android/issues/detail?id=2863">http://$c$c.google.com/p/android/issues/detail?id=2863

There is an issue with the include tag. Check: http://code.google.com/p/android/issues/detail?id=2863

要解决这个问题,一定要覆盖其中 layout_width layout_height 包括什么时候,否则一切都将被忽略。

To fix it, make sure you overwrite BOTH layout_width and layout_height when including, otherwise everything will be ignored.

这篇关于如何获得RelativeLayout的合作与合并,包括?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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