2010-04-13 4 views
0

화면의 가운데에있는 TextView의 왼쪽에 Button을 레이아웃하려고합니다. 내 레이아웃은 다음과 같습니다.RelativeLayout에서 layout_toLeftOf를 사용하여 레이아웃 한 버튼이 표시되지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="foo" 
    android:id="@+id/center" 
    /> 

    <Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Left button" 
    android:layout_toLeftOf="@id/center" /> 
</RelativeLayout> 

불행히도 버튼이 나타나지 않습니다. 다음과 같은 결과가 나타납니다. alt text

보시다시피 버튼이 표시되지 않습니다. layout_toRightOf를 사용하면 작동합니다. 그러면 버튼이 예상대로 TextView 오른쪽에 나타납니다.

내가 여기서 잘못하고있는 아이디어가 있습니까?

답변

2
  1. 을보십시오. TextView의 가운데 맞춤을 사용하려면 예 : android:layout_centerInParent="true"
  2. Button의 수직 배치에 대한 규칙을 제공하지 않았습니다.
  3. hierarchyviewer을 사용하여 레이아웃을 검사하여 사물의 위치를 ​​파악합니다. 당신이 원하는 곳 또한 패드 텍스트가 이동하는 수
+0

게시물을 통해 안드로이드의 레이아웃에 대해 거의 알지 못한다는 것을 알게되었습니다. 유용한 포인터를 가져 주셔서 감사합니다. – rodion

+0

@CommonsWare - 예전에 대답 해 봤지만이 답변이 거의 주어지지 않았고 찾기가 얼마나 힘든지 놀랍습니다. 정말 고맙습니다! LinearLayouts에 정크를 재 작업 한 날을 저장했습니다. –

+1

@WesWinn :이 질문은 너무 오래되었지만, 스크린 샷에서 본 것처럼 에뮬레이터가 본 모습을 잊어 버렸습니다. :-) 도움이 되었다니 기쁜 소식입니다! – CommonsWare

1

당신은 TextView 위치에 대한 어떤 규칙을 제공하지 않은

<Button android:id="@+id/button" 
    android:layout_alignParentLeft="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Left button"> 
</Button> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="foo" 
    android:layout_toRightOf="@id/button" 
    android:id="@+id/center"> 
</TextView> 
+0

Rpond, 당신의 응답을 주셔서 감사합니다. 귀하의 제안에 따라 TextView가 더 이상 화면 중앙에 오지 않습니다. TextView가 중앙에 배치되도록하는 방법은 무엇입니까? 감사. – rodion

0

...

관련 문제