2013-05-22 64 views
1

对不起,我因为我的大内容是在Android的在另一个叫Android的布局,使嵌套布局

新的,我要创建一个ScrollView。通过这种方式,我在1个文件中创建了一些我的内容的部分(我们称之为FirstLayout.xml),另一部分为SeconedLayout.xml。现在我在一个单一的XML文件来调用他们两个。(Parent.xml

但问题是,我不知道,我应该怎么称呼他们,我滚动型

这里是代码

FirstLayout.xml

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
. 
. 
. 
</AbsoluteLayout> 

SeconedLayout.xml是:

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

Parent.xml

可见

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroller" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

<!-- Call FirstLayout --> 


<!-- Call SecondLayout --> 
</ScrollView> 
+0

使用<包括布局=“@布局/标题栏” />这样 – Raghunandan

+0

使用''标签 – Geros

+0

您需要包括运行时或之前的时间... –

回答

1

可以包括布局像

<include layout="@layout/FirstLayout" /> 

<include layout="@layout/SeconedLayout" /> 

所以你的布局应该像

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/scroller" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 
    <include layout="@layout/FirstLayout" /> 

    <include layout="@layout/SeconedLayout" /> 
    </LinearLayout> 
    </ScrollView> 
+0

我做了它,但它给了我错误,说:_“ScrollView只能支持一种布局”_所以我把它们放在_LinearLayout_中,而不仅仅是第一个布局显示??! – Salman

+0

看到编辑答案 –

2

你应该使用包括标签:

<include 
    layout="@layout/SeconedLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
+0

只需添加此代码并为其他布局执行相同的操作。 – Sandeep

0

使用包括标签,如

<include layout="@layout/firstlayout" /> 
0

尽量只使用包括这样的标签:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroller" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 
<include layout="@layout/FirstLayout" /> 
<include layout="@layout/SeconedLayout" /> 
</ScrollView> 

但获得更好的性能,使用标签,这有助于消除您的视图层次多余的视图组包括内另一个布局时。看看here