2016-03-09 164 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以獲得佈局在中心只是一種僥倖。它將出現在不同分辨率手機的不同位置。 –