2011-09-19 4 views
1

다음 레이아웃을 만들려고합니다.Android : 중간 구성 요소가있는 레이아웃 확장

+---------------------+ 
|  Text View  | 
+---------------------+ 
|      | 
|      | 
| Custom View  | 
| Expands to  | 
| extra space  | 
|      | 
+---------------------+ 
|Button1 |Button2 | 
+---------------------+ 

내 레이아웃 xml은 다음과 같습니다.

<?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:text="This is test text." android:id="@+id/statusTxt" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" /> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:id="@+id/gameView" 
     android:layout_gravity="bottom"> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:id="@+id/gameButtonView"> 

      <Button android:text="Done" android:id="@+id/doneBtn" 
       android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 

      <Button android:text="Undo" android:id="@+id/undoBtn" 
       android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

는 프로그래밍 방식보다 나는이처럼 보이는 끝나는 현재 레이아웃으로 내 사용자 정의보기

LinearLayout gameView = (LinearLayout)this.findViewById(R.id.gameView); 
gameView.addView(gameBoardView, 1); 

를 추가하고있다. 이 현재의 레이아웃이 무엇

+---------------------+ 
|  Text View  | 
+---------------------+ 
|Button1 |Button2 | 
+---------------------+ 
|      | 
|      | 
| Custom View  | 
| Expands to  | 
| extra space  | 
|      | 
+---------------------+ 

은 사용자 정의보기 위 아래 버튼을 스틱입니다. 내가 어떻게 묘사했는지 렌더링 할 수있는 방법에 대한 아이디어가 있습니까?

+0

당신은 할 수 없습니다 그냥 안드로이드 꺼내 : layout_gravity = "하단"당신은 중간 LinearLayout에 있나요? – brianestey

답변

6

RelativeLayout을 사용하십시오. TextView를 alignParentTop = "true"로 설정하십시오. 이런 = "true"로하고 위 = "버튼"에 중간에 콘텐츠를 설정하고 아래 = "텍스트"alignParentBottom와의 LinearLayout에 버튼을 넣어

뭔가 :

<?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"> 

    <!-- Text at the top --> 
    <TextView 
     android:id="@+id/text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 

    <!-- Your game play view --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/buttons" 
     android:layout_below="@+id/text" /> 

    <!-- Buttons at the bottom --> 
    <LinearLayout 
     android:id="@+id/buttons" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

     <Button 
      android:layout_weight="1" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:layout_weight="1" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

</RelativeLayout> 
+0

주어진 예제를 사용하여 프로그래밍 방식으로 View 요소를 내 사용자 정의보기로 설정하려면 어떻게해야합니까? 그 외에는 당신의 대답이 효과가 있다고 생각합니다. – EpicOfChaos

+0

그래서 여기에 그 문제가 있습니다. 프로그래밍 방식으로 LayoutParams의 위/아래 모든 것을 설정할 수 있지만 엉덩이의 고통입니다. 이드가있는 공간에 LinearLayout을 놓은 다음, LinearLayout의 내용을 게임 뷰 (removeView와 removeView의 새로운 뷰를 바꾸려는 경우 addView가 뒤따라야 함)로 바꾸십시오. 그렇게하면 코드에서 LayoutParams를 사용하여 멋지게 할 필요가 없습니다. FILL_PARENT, FILL_PARENT로 인스턴스화하면 완료됩니다. – Rich

+1

완벽하게 작동합니다. 빠른 응답과 상세한 예제 덕분입니다. 당신은 안드로이드 커뮤니티의 훌륭한 멤버입니다. – EpicOfChaos

관련 문제