2016-03-09 166 views
0

布局应该在第一个布局底部对齐一半,在第二个布局顶部对齐一半,我对搜索没有任何线索。任何人都帮助我! ![See the image for better idea] 1Android如何在两个布局顶部布局布局

+1

它很容易的兄弟......首先你尝试过什么? –

+1

你有没有做过任何初始代码?你可以发布吗?并明确回答这个问题..只需使用*** RelativeLayout ***作为主要的父母布局。 –

+0

Framelayout可以用来创建这个。 http://developer.android.com/reference/android/widget/FrameLayout.html – Stallion

回答

3

这将在所有的决议,工作正确的 -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="5"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_margin="5dp" 
     android:layout_weight="3" 
     android:background="#000000" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_margin="5dp" 
       android:layout_weight="1" 
       android:background="#000000" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_margin="5dp" 
       android:layout_weight="1" 
       android:background="#000000" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="150dp" 
      android:layout_height="100dp" 
      android:layout_centerInParent="true" 
      android:background="@color/colorAccent" /> 

    </RelativeLayout> 

</LinearLayout> 
+1

这将适用于所有分辨率 –

+0

这对所有分辨率,一点寿,我编辑它删除最外面的RelativeLayout。只是等待审稿人确认.. :) –

+0

是!工作正常。我只想要这个肖像模式。谢谢@Jyotman Singh –

3

所以我继续尝试了这一点,并成功地做这样的事情..

enter image description here

下面是一个简单的代码,以帮助您:

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="5"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_margin="5dp" 
      android:layout_weight="3" 
      android:background="#000000" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:background="#000000" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:background="#000000" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="150dp" 
     android:layout_height="100dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="50dp" 
     android:background="@color/colorAccent" /> 

</RelativeLayout> 

有关如何使用RelativeLayout的更多信息,可以查看官方Android开发者网站 - RelativeLayout。 希望这有助于。

+0

好的工作@ sept。 –

+0

@Amit Vaghela谢谢! :) –

+0

对不起@ sept,但我不知道为什么这是upvotes。这是错误的。设置marginBottom 50dp以获得布局在中心只是一种侥幸。它将出现在不同分辨率手机的不同位置。 –