2013-11-26 53 views
0

后如预期这是我的布局XML:布局未设置添加规则相对布局

<LinearLayout 
    android:id="@+id/layoutMenuContainer" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <fragment 
     android:id="@+id/frgMenu" 
     android:layout_width="200dip" 
     android:layout_height="match_parent" 
     class="com.narola.fragments.MenuFragment" /> 
</LinearLayout> 

    <RelativeLayout 
     android:id="@+id/layoutHomeContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true" > 

     <fragment 
      android:id="@+id/frgHeader" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      class="com.narola.fragments.HeaderFragment" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/frgHeader" 
      android:background="@android:color/black" > 
     </LinearLayout> 
    </RelativeLayout> 

这是上面的XML结果:

enter image description here

现在这上面的布局我设置android:layout_toRightOf="@+id/layoutMenuContainer"属性的相对布局(android:id="@+id/layoutHomeContainer")而不是父顶端:

<LinearLayout 
     android:id="@+id/layoutMenuContainer" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" > 

     <fragment 
      android:id="@+id/frgMenu" 
      android:layout_width="200dip" 
      android:layout_height="match_parent" 
      class="com.narola.fragments.MenuFragment" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/layoutHomeContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@+id/layoutMenuContainer"> 

     <fragment 
      android:id="@+id/frgHeader" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      class="com.narola.fragments.HeaderFragment" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/frgHeader" 
      android:background="@android:color/black" > 
     </LinearLayout> 
    </RelativeLayout> 

结果是:

enter image description here

,而不是向下滑动则运算其父布局视图的右视图。为什么会发生?我该如何解决这个问题。

+1

你能解释一下这条线吗? “而不是向下滑动正确的视图,它正在处理其父视图中的视图” –

+0

意味着正确的布局宽度与边界相匹配,因为您可以在布局中看到我想要的是不想更改宽度只是x的位置正确的看法。 – KDeogharkar

回答

0

根据你的评论,你应该尝试在你的RelativeLayout中使用android:layout_marginRight="20dp"。这里20dp是例如。

0

您应该尝试更改父匹配父项到包装内容的父相对布局的宽度。