2012-10-28 4 views
6

2 개의 이미지가 포함 된 내부 상대적 레이아웃이 있고 android : layout_marginRight 속성을 설정하면 아무 것도하지 않습니다. 그냥 당신이 당신의 이미지 뷰의 오른쪽에서 마진을 얻을 것이다이 줄을 제거 android : layout_marginRight 속성이 RelativeLayout에서 작동하지 않습니다.

android:layout_alignParentRight="true" 

을 일어나는 이유를 다음과 같은 먹으 렴을 사용했다

<RelativeLayout 
    android:id="@+id/location_image_layout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="80dp" /> 

    <ImageView 
     android:layout_width="69.33dp" 
     android:layout_height="72dp" 
     android:background="@drawable/icon" 
     android:layout_centerInParent="true" /> 

</RelativeLayout> 
+0

달성하려는 것은 무엇입니까? – wtsang02

+0

상단 이미지가 두 번째 이미지의 왼쪽에 있고 두 번째 이미지의 맨 아래에 정렬하고 싶습니다. – meh

+0

좋은 답변이 많이 있습니다. 당신이 좋아하는 답변을 upvote하는 좋은 연습. – Siddharth

답변

21

문제는 레이아웃의 속성 android:layout_width에 있습니다. "wrap_content"으로 설정하면 android:layout_marginRight이 작동하지 않고 "fill_parent"으로 설정된 경우에만 android:layout_marginRight이 작동합니다.

+0

(2017 년) : API> = 17이면 android : layout_marginEnd를 사용할 수 있습니다. API 8부터는 "fill_parent"가 아닌 "match_parent"를 사용해야합니다. – PedroHidalgo

0

.. :

여기 내 코드입니다

+0

레이아웃을 오른쪽으로 정렬해야합니다. – meh

1
<LinearLayout 
    android:id="@+id/location_image_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right" 
    android:orientation="vertical" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="80dp" /> 

    <ImageView 
     android:layout_width="69.33dp" 
     android:layout_height="72dp" 
     android:background="@drawable/icone" 
     android:layout_centerInParent="true" /> 

</LinearLayout> 

시도해보십시오. 그것은 나를 위해 당신이 원하는 정확히 일치

-4

레이아웃에서 여백을 적용하기 위해 RelativeLayout 대신 LinerarLayout을 사용해보십시오.

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    ... 
/> 

동일한 문제가 발생하며 부모 RelativeLayout의 layout_width를 "match_parent"로 변경하면 작동합니다. 그것이 당신을 위해 또한 작동하기를 바랍니다.

관련 문제