2011-06-14 9 views
2

이 XML을 사용하여 아래쪽에 Button 한 개를 표시하고 맨 위에 TextView 한 개를 표시하고 중간에 TextView 개를 표시합니다. 중간 텍스트 뷰는 버튼과 상단 텍스트 뷰 사이의 전체 범위를 포함합니다. 가운데 TextView이 전혀 표시되지 않습니다. 뭐가 잘못 되었 니?상대 레이아웃, Textview가 표시되지 않음

<?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"> 
    <TextView 
     android:id="@+id/task" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/tasks" 
     /> 
    <Button 
     android:id="@+id/btnAddTask" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/AddTasks" 
     android:layout_alignParentBottom="true" 
     /> 
    <TextView 
     android:id="@+id/TasksList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/tasks" 
     android:layout_above="@id/task" 
     android:layout_below="@id/btnAddTask" 
     /> 
</RelativeLayout> 
+1

+1 중재자를 괴롭히지 않고 코드 태그에 전체 코드를 표시합니다. –

답변

2

귀하의 문제는 당신이 당신의 버튼을 아래 TasksList 텍스트 뷰를 가지고 확실히이다. layout_above 및 layout_below 값을 서로 바꿉니다. 이 작품은 나를 위해 :

<?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"> 
    <TextView 
     android:id="@+id/task" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/tasks" 
     /> 
    <Button 
     android:id="@+id/btnAddTask" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/AddTasks" 
     android:layout_alignParentBottom="true" 
     /> 
    <TextView 
     android:id="@+id/TasksList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/tasks" 
     android:layout_above="@id/btnAddTask" 
     android:layout_below="@id/task" 
     /> 
</RelativeLayout> 
1

어떻게 배치했는지 분명히 잘못되었습니다.

당신은 버튼을 가지고 alignParentBottom="true" ... 그런 다음 TasksList TextView에 대해 버튼 아래에 기본적으로 설정되어 있지 않습니다.

RelativeLayout에서 오리엔테이션을 제거 할 수 있습니다 ... 상대적인 레이아웃에는 LinearLayout의 것과 같은 방향이 없습니다.

설명하시는대로 ... 나는 Relative Layout으로 100 % 할 수 없습니다. 위쪽에 하나, 가운데에 하나, 아래쪽에 하나씩 싶으면 각각 하나의 레이아웃 매개 변수 인 centerInParent, alignParentTopalignParentBottom을 사용하는 것이 가장 좋습니다.

당신이 수직 방향으로 다루고 싶어요 (난 당신이 시작 짐작으로) 당신이 LinearLayout을 다시 생각하면, 그들에게 높이를 wrap_content로 설정하고 확인하는 0의 layout_weight, 1, 0을 제공합니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView 
     android:id="@+id/task" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     /> 
    <TextView 
     android:id="@+id/TasksList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/tasks" 
     android:layout_weight="1" 
     /> 
    <Button 
     android:id="@+id/btnAddTask" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/AddTasks" 
     android:layout_weight="0" 
     /> 
</LinearLayout> 
1

당신이 위의 레이아웃을 반전 문제의 WSA 아래 레이아웃 :

android:layout_below="@id/task" 
android:layout_above="@id/btnAddTask" 

페이지의 스크린 샷을 시도해보십시오.

다음은 전체 레이아웃입니다.

<?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"> 
    <TextView 
     android:id="@+id/task" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/tasks" 
     /> 
    <Button 
     android:id="@+id/btnAddTask" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/AddTasks" 
     android:layout_alignParentBottom="true" 
     /> 
    <TextView 
     android:id="@+id/TasksList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/tasks" 
     android:layout_below="@id/task" 
     android:layout_above="@id/btnAddTask" 
     /> 
</RelativeLayout> 

enter image description here

+1

그건 OP가 요구하는 것 ... 3 개의 전망이 있어야하는데 ... 2 TextViews와 1 Button. – Maximus

+0

나는 회색으로 된 맨 위가 활동 제목 ...이 레이아웃의보기 중 하나가 아니라고 생각합니다. – Maximus

+0

좋습니다. 나는 충분한주의를 기울이지 않았다. 위의 수정 사항을 게시하고 새로운 화면을 잡았습니다. –