2016-11-14 50 views
0

重叠视我有以下布局结构:如何避免RelativeLayout的

<RelativeLayout> 
    <ScrollView> 
     <LinearLayout> 
      <RelativeLayout> 
       <LinearLayout android:id="@+id/ContentNo1"> <-- Align top 
       </LinearLayout> 
       <LinearLayout android:id="@+id/ContentNo2"> <-- Align bottom 
       </LinearLayout> 
      </RelativeLayout> 
     </LinearLayout> 
    </ScrollView> 
    <Button/> <-- Always bottom of the page 
</RelativeLayout> 

我的按钮是底端对齐在第一RelativeLayout的,和我的滚动型顶端对齐在它...

我想在第二个RelativeLayout中将ContentNo1顶部对齐,并在底部对齐ContentNo2 ...

我已经这样做了,但是当ContentNo1变得太大,它与ContentNo2重叠时,我希望它只是推送ContentNo2下...如何做到这一点?

我已经试过(如在某些话题在这里详细介绍),使用layout_below/layout_above,但是当我使用它时,ContentNo2的下对齐被解雇......

- 编辑 -

由于瓦斯问,这里是一些图片:(我不能发布超过2个链接,然后我做了这个网页来解释它)

http://www.mydonorlife.hol.es/relativeissue/

- EDIT 2 - 解决方案 -

这个工作对我说:我已经删除了第二RelativeLayout的,并设置一些看法如下>>

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_alignParentTop="true" 
     android:fillViewport="true"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
                <!-- CONTENT NO 1 --> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_marginBottom="30dp"> 
      </LinearLayout> 
                <!-- /CONTENT NO 1 --> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:orientation="vertical" 
       android:layout_weight="1" 
       android:layout_height="0dp"> 
                <!-- CONTENT NO 2 --> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:gravity="bottom" 
        android:layout_height="match_parent" 
        android:layout_weight="0"> 
       </LinearLayout> 
                <!-- /CONTENT NO 2 --> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 
    <Button 
     android:layout_alignParentBottom="true"/> 
</RelativeLayout> 

希望它的一些体重/身高的技巧帮助别人后...

+0

您可以使用匹配父外的LinearLayout,使其全屏幕,然后用layout_below/layout_above。然后底部对齐不会消失。因为使用layout_below/layout_above可以确保两个相对布局之间没有重叠。 –

+0

这外的LinearLayout已经设置与match_parent高度和底部对齐不断消失,当我使用layout_below /上述 –

+0

下对齐消失意味着内容2是无法适应屏幕的休息吗?你能分享一张照片吗?一张图片可能会更好地描述这个问题! –

回答

1

我已经改变了一些代码,并尝试做一个布局,只要你想。

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <ScrollView 
      android:id="@+id/scrollview" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_alignParentTop="true" 
      android:fillViewport="true"> 
      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
       <!-- CONTENT NO 1 --> 
       <LinearLayout 
        android:id="@+id/linerlayout" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" 
        android:layout_marginBottom="30dp"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Top aligned text1"/> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Top aligned text2"/> 
       </LinearLayout> 
       <!-- /CONTENT NO 1 --> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:orientation="vertical" 
        android:layout_below="@+id/linerlayout" 
        android:layout_height="wrap_content"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="bottom aligned text1"/> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="bottom aligned text2"/> 
        <!-- CONTENT NO 2 --> 
        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="match_parent" 
         android:gravity="bottom" 
         android:layout_height="match_parent" 
         android:layout_weight="0"> 
        </LinearLayout> 
        <!-- /CONTENT NO 2 --> 
       </LinearLayout> 
      </RelativeLayout> 
     </ScrollView> 
     <Button 
      android:layout_alignBottom="@id/scrollview" 
      android:text="bottom button" 
      android:layout_alignParentBottom="true" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      /> 
    </RelativeLayout> 

,你还可以添加您含量无1含量没有2 UI按照您的要求

+0

真棒,这也确实很好 –

+0

@ T.Lima感谢他们加入。 –