2014-01-12 3 views
0

선형 레이아웃에서 레이아웃 가중치를 알고 있습니다. 상대 레이아웃에서 레이아웃 가중치를 할당 할 수 있습니까?상대 레이아웃의 레이아웃 가중치

예 : 레이아웃을 비율 60:40으로 채우는 레이아웃의 두 이미지보기. 첫 번째 이미지는 전체 화면 높이의 60 %를 차지해야하며 두 번째 이미지는 화면의 나머지 40 %를 차지해야합니다.

이 예제만으로는 문제를 해결할 수 없으며, 상대적 레이아웃에서 레이아웃 가중치에 대한 참조 링크를 게시하거나 정확하게 알려주십시오. 미리 감사드립니다.

+0

아니요. relativelayout과 함께 작동하지 않습니다. reference http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html and this 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을 사용할 수 없지만 상대적 레이아웃과 선형 레이아웃을 함께 사용하면 두 가지 장점을 모두 누릴 수 있습니다.

팁 : 여러 개의 화면을 측정해야하므로 UI가 느려지지 않도록 가능한 한 적은 레이아웃으로 사용해보십시오! [1][2]

0

상대 레이아웃에는 가중치가 필요하지 않습니다. 이미지 뷰를 따라 이동하여 이미지 뷰가 올바른 비율을 유지하는지 확인할 수 있습니다. 가중치는 LinearLayout에서만 사용됩니다.

관련 문제