마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

텍스트뷰와 이미지뷰가 양쪽 정렬이 안되는 현상

0 추천
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/bottom_menu"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:orientation="horizontal"
	android:background="@color/white"
	android:layout_gravity="right"
	android:layout_marginBottom="5dp">
		<TextView
			android:id="@+id/title_text"
		    android:layout_width="wrap_content"
		    android:layout_height="wrap_content"
		    android:layout_weight="1"
			android:layout_gravity="center_vertical|left"
		    android:text="카드 정보"
		    android:textColor="#000000"
		    android:textSize="20dp"
		    android:textStyle="bold" />
		<LinearLayout 
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
		    android:layout_weight="1"
		    android:gravity="center_vertical|right"
			android:layout_margin="5dp">			    
			<ImageView 
				android:id="@+id/menu"
				android:layout_width="20dp"
				android:layout_height="20dp"
				android:src="@drawable/ic_menu_selector"/>
		</LinearLayout>
</LinearLayout>

위의 xml파일로 작성했을 때 Graphical layout에서는

제가 원하는 의도대로 텍스트뷰와 이미지뷰가 양쪽정렬이 되서 나옵니다.

 

하지만

	<com.test.activity.TopMenuLayout
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"/>
저는 이런 식으로 위의 레이아웃을 inflate 하여 title bar로써 activity를 새로 만들어 컨트롤 하고 싶은데요
다른 activity에 TopMenuLayout을 inflate 하면
 
 
이런식으로 모두 왼쪽정렬이 되어버리네요
 
소중한 조언 부탁드립니다.

 

까먹지 (3,960 포인트) 님이 2014년 3월 10일 질문

2개의 답변

+1 추천
inflate  하는 view 부분에 programmatically 하게  match_parent 를 추가하세요
aucd29 (218,390 포인트) 님이 2014년 3월 11일 답변
http://imgur.com/rw20IAc
match_parent를 모든 경우의 수에 넣어봐도 결과는 같네요ㅠㅠ
programmatically 은 xml 에서 넣는게 아니고 코드상에서 넣는 것이구요
inflate 시에는 view 에 따로 설정해야 그 값이 적용 됩니다.
+1 추천
최상위 Layout을 LinearLayout 대신에 RelativeLayout을 사용해 보세요.
익명사용자 님이 2014년 3월 11일 답변
RelativeLayout으로 layout_alignParentRight 속성 사용해서 해결 했습니다.
두분 다 감사드립니다^^
...