2013-04-15 3 views
0

선형 레이아웃이고 텍스트보기와 이미지보기가있는 헤더가 있습니다. 헤더의 크기가 증가가의 이미지 뷰가 왼쪽으로 약간 이동하기 때문에 세로 모드에서선형 레이아웃의 오른쪽에 이미지보기 고정 안드로이드

< LinearLayout 
<TextView 
    android:layout_weight="8" 
    ... 
/> 
<ImageView 
    android:layout_weight="2" 
... 
/> 
</LinearLayout> 

, 모든 것이 완벽하지만 가로 모드입니다.

방향에 관계없이 이미지보기를 머리글의 오른쪽으로 고정 할 수 있기를 원합니다.

할 방법이 있습니까?

+2

을 RelativeLayout 사용에 대해 생각하고 싶을 수 있습니다. 그렇다면 android : alignParentRight = "true" – atreat

+0

루트 레이아웃이 상대적이라면 textview를 android : alignParentLeft로 설정하고 imageview의 id를 넣어서 android : layout_toLeftOf를 설정할 수 있습니다. 그리고 물론 imageview에 대한 매개 변수를 'android : alignParentRight' true로 설정합니다. – deadfish

답변

0

ImageView의 layout_width 및 layout_height를 "wrap_content"로 설정하고 layout_weight를 제거하십시오. 그렇게하면 TextView는 ImageView 왼쪽의 사용 가능한 모든 공간을 채 웁니다.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 
    <TextView 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
    /> 
    <ImageView 
     android:src="@drawables/my_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
    /> 
</LinearLayout> 
0

사용이

< LinearLayout 
...> 
<TextView 
    android:layout_weight="8" 
    ... 
/> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="2" 
    > 
    <ImageView 
     android:alignParentRight="true" 
     ... 
    />  
</RelativeLayout> 

</LinearLayout> 
0

아래의 코드를 추가, 그것은 texView에 사용 가능한 모든 공간 레이아웃의 오른쪽에 이미지 뷰를 이동 할당합니다 :

< LinearLayout 
<TextView 
android:layout_weight="1" 
... 
/> 
<ImageView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
/> 
</LinearLayout> 
관련 문제