2014-01-12 135 views
0

我知道線性佈局中的佈局權重。我可以在相對佈局中分配佈局權重嗎?相對佈局中的佈局權重

示例:以60:40的比例填充佈局的佈局中的兩個圖像視圖。第一張圖片佔用整個屏幕高度的60%,第二張圖片佔據屏幕剩餘的40%。

不要只爲這個例子問題單獨回答,請精確告訴我這個概念,或者在相對佈局中發佈一些關於佈局權重的參考鏈接。提前致謝。

+0

不,它不會與relativelayout工作。參考http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html和這個http://developer.android.com/reference/android/widget/RelativeLayout.html – Raghunandan

+0

請參考這個答案文章: http://stackoverflow.com/questions/14009230/relativelayout-weight – AmiNadimi

回答

2

您可以在佈局的中心放置一個不可見的視圖,並將您的視圖左右對齊。這裏是一個例子

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toLeftOf="@+id/view" 
     android:background="#fffba2" /> 

    <View 
     android:id="@+id/view" 
     android:layout_width="1dp" 
     android:layout_height="1dp" 
     android:layout_centerHorizontal="true" 
     android:visibility="invisible" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@+id/view" 
     android:background="#ba2fff" /> 

</RelativeLayout> 
0

實際上,您不能在RelativeLayout中使用weight,但您可以使用相對和線性佈局的組合,以充分利用它們!

提示:儘量使用盡可能少的佈局以避免用戶界面過慢,因爲多屏幕測量! [1][2]

0

在相對佈局中不需要權重。您可以移動圖片視圖以確保它們的比例正確。權重僅用於LinearLayout。