2017-05-03 65 views
1

enter image description here如何將一個相對佈局與另一個相對佈局的中間對齊。如果兩個相對佈局都是兄弟姐妹? 我已經嘗試了多種東西,但是我找不到任何東西。 我需要將一個片段的中心與另一個片段的中間對齊,並且此第二個片段可以在運行時更改大小。因爲它有一些開關來啓用和禁用某些視圖。Allign two relative Layout

F1始終是固定的,我需要改變F2的位置,使得它的中心總是與我都試過東西給你下

+0

你能提供一些草圖,以便更好地理解問題嗎? –

+0

你可以發佈你嘗試過的XML嗎? – Lingeshwaran

+0

@android_griezmann請檢查我的問題現在是否清楚 – RATHI

回答

0

的F1結束對齊。

<?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" 
    android:orientation="vertical"> 

<RelativeLayout 
    android:id="@+id/f1" 
    android:layout_width="100dp" 
    android:layout_height="200dp" 
    android:layout_alignBottom="@+id/holder" 
    android:layout_centerVertical="true" 
    android:layout_toLeftOf="@+id/holder" 
    android:background="@color/colorPrimary"></RelativeLayout> 

<View 
    android:id="@+id/holder" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_centerInParent="true" /> 

<RelativeLayout 
    android:id="@+id/f2" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_centerVertical="true" 
    android:layout_toRightOf="@+id/holder" 
    android:background="@color/colorPrimary"></RelativeLayout> 

</RelativeLayout> 

注意:高度&寬度可以根據您的要求進行設置。要檢查您的問題是否已解決,請嘗試增加f2佈局的降低高度。

希望這適合你!

+0

在我的問題中,F1總是固定的,我需要改變F2的位置,使它的中心始終與F1底部的末端對齊。 – RATHI

+0

你也可以讓F1修理,我已經修好了! –