2011-05-09 4 views
2

나는 2 개의 수직 세그먼트로 화면을 나누고 싶습니다. 하단 툴바가 수정되어야합니다. LinearLayout이 무엇이든 상관없이 아래쪽에 머무르게하고 싶다고합시다.화면 레이아웃. 하단에 머물 도구 모음이 필요합니다

맨 위로 - 도구 모음으로 커지고 스크롤을 허용하는 ScrollView가 필요합니다. 그렇지 않으면 - 완전히 비어있을 수 있지만 도구 모음은 여전히 ​​바닥에 있어야합니다.

어떻게하면됩니까?

답변

7

항상 그렇듯이 몇 가지 방법이 있습니다. 나는이

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 
     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1"> 
     </ScrollView> 
     <LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent"> 
     <Button 
      android:text="Button1" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content"/> 
     <Button 
      android:text="Button2" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content"/> 
     </LinearLayout> 
</LinearLayout> 

이 수직 선형 레이아웃을 사용하고 wrap_content를 사용하여 하단에있는 버튼을두고 다음, 다음을 "1"의 가중치를 부여하여있는 ScrollView에게 나머지 공간을 제공 할 것입니다.

+0

만약 내가 1000 upvotes 대답 줄 수, 나는 것입니다. 나는이 레이아웃이 잠시 동안 제대로 작동하도록 싸워왔다. (여전히 안드로이드 레이아웃에 다소 새로운). 이것은 훌륭하게 작동했습니다. –

0

두 번째 LinearLayout에서 두 개의 버튼이있는 것은 안드로이드 : layout_alignParentBottom = "true"입니다.

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

    <ScrollView android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:layout_marginTop="5dp" 
     android:layout_marginBottom="60dp" android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp"> 

     <LinearLayout android:orientation="vertical" 
      android:layout_width="fill_parent" android:layout_height="wrap_content"> 

      <TextView android:layout_width="fill_parent" 
       android:layout_height="wrap_content" android:text="Some text" /> 

     </LinearLayout> 
    </ScrollView> 

    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:paddingTop="5dp" 
     android:layout_alignParentBottom="true" android:layout_marginTop="5dp"> 

     <Button android:id="@+id/ok_button" android:layout_width="fill_parent" 
      android:layout_weight="1" android:layout_height="wrap_content" 
      android:text="OK" android:layout_alignParentLeft="true" /> 

     <Button android:id="@+id/cancel_button" android:layout_width="fill_parent" 
      android:layout_weight="1" android:layout_height="wrap_content" 
      android:text="Cancel" android:layout_toRightOf="@id/ok_button" /> 
    </LinearLayout> 
</RelativeLayout> 
관련 문제