2013-08-29 4 views
11

Android 응용 프로그램을 개발하려고하지만 GUI 디자인에 문제가 있습니다. 스크린 샷의 다음 부분은 내 문제입니다 (빨간색과 파란색 선은 Android 디버그 옵션에 의해 생성되었습니다). 당신이 볼 수 있듯이RelativeLayout에서보기가 겹치지 않도록하기

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/caption" 
    android:layout_below="@+id/caption" > 

    <ImageButton 
     android:id="@+id/button_edit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/content_edit" 
     style="?android:attr/borderlessButtonStyle" /> 

    <TextView 
     android:id="@+id/myText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:text="@string/num_placeholder" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 


</RelativeLayout> 

에서, 텍스트 뷰 myText를가하여 ImageButton의 button_edit 겹치는 :

my problem

는 코드입니다. 간단한 해결책은 RelativeLayout 대신 LinearLayout을 사용하는 것입니다.

  1. 내가
  2. 가 나는 또한

나는 (분명히 편집 버튼의 왼쪽에) 레이아웃의 나머지 부분을 채우기 위해 텍스트를 필요 오른쪽에있는 편집 버튼을해야 문제가 있다는 것입니다 myText의 layout_width를 'fill_parent'로 설정하려고했지만 편집 버튼의 왼쪽에 전체 화면을 채 웁니다.

예상되는 동작 (두 줄 텍스트 뷰가되는) 대신 'button_edit'

이 사람이 나를 도울 수를 중복 높이를 증가 myText를 할 것인가? 텍스트 뷰 레이아웃에 감사

+0

왜 'RelativeLayout'을'LinearLayout'으로 구현할 수 있습니까? – sriramramani

답변

19

사용 layout_toLeftOf이 같은

는 :

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignLeft="@+id/caption" 
android:layout_below="@+id/caption" > 

<ImageButton 
    android:id="@+id/button_edit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/content_edit" 
    style="?android:attr/borderlessButtonStyle" /> 

<TextView 
    android:id="@+id/myText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:text="@string/num_placeholder" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_toLeftOf="@+id/button_edit" /> 

+0

감사합니다. 그것은 완벽하게 작동합니다! – Gnufabio

+0

동적으로 생성 된 뷰를 사용하여이 작업을 수행하려면 어떻게해야합니까? –

0

하고있는 또 다른 방법은 안드로이드를 사용하는 것입니다 : 속성 layout_toEndOf

<ImageButton 
    android:id="@+id/button_edit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/content_edit" 
    style="?android:attr/borderlessButtonStyle" 
    android:layout_toEndOf="@+id/myText" /> 

<TextView 
    android:id="@+id/myText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:text="@string/num_placeholder" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

관련 문제