2011-12-29 1 views
0

현재 화면을 세 부분으로 나누고 싶은 Android 프로젝트를 진행 중입니다.스크롤 센터가있는 세 가지 구성 요소 사용자 인터페이스

첫 번째 섹션은 화면 상단에 위치하지 않는 제목입니다. 두 번째 섹션은 스크롤 할 수있는 주요 콘텐츠입니다. 세 번째 섹션은 화면 하단에 고정 된 두 개의 버튼입니다.

이 설정에서 상단 및 하단은 화면에 머물러 있으며 화면의 중앙 부분 만 스크롤 할 수 있습니다.

웬일인지, 내가 이것을하려고 노력했을 때, 정상이고 중간의 일은 벌금 그러나 버튼을 가지고있는 바닥은 결코 보이지 않고 있었다. 다음은

난 당신이 제공 할 수있는 어떤 도움이 작업

<?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="wrap_content" 
     android:orientation="vertical"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_eulaTitle" 
      android:textSize="15dp" 
      android:textStyle="bold" /> 
     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent"> 
      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/start_eula" /> 
     </ScrollView> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
     <Button android:id="@+id/start_btnAgree" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/button_agree" /> 
     </LinearLayout> 
    </LinearLayout> 

감사를 얻으려고하는 데 사용한 코드입니다.

답변

0

RelativeLayout은 아마도 당신이 찾고있는 것을 성취하기위한 방법 일 것입니다. 같은 : 제목 텍스트 뷰는 기본적으로 왼쪽 상단에 앉아 반면이 기본적으로 버튼으로있는 LinearLayout을 알려줍니다

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

    <TextView 
     android:id="@+id/title_textview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/start_eulaTitle" 
     android:textSize="15dp" 
     android:textStyle="bold" /> 

    <ScrollView 
     android:id="scrolling_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/button_layout" 
     android:layout_below="@+id/title_textview" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_eula" /> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/button_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/button_agree" /> 

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/button_agree" /> 
    </LinearLayout> 

</RelativeLayout> 

항상 화면 하단에 정렬합니다. 스크롤 가능한 영역은 제목 아래이지만 버튼 위에있는 두 개의 중간에 있도록 정의됩니다.

// 편집 : 당신이 정말 루트로 LinearLayout을 고수 할 경우에는 다음과 같이 잠재적으로 수 :

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/start_eulaTitle" 
     android:textSize="15dp" 
     android:textStyle="bold" /> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_eula" /> 
    </ScrollView> 

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

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="@string/button_agree" 
      android:layout_weight="1"/> 

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="@string/button_agree" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</LinearLayout> 

마법이있는 ScrollView에 1의 가중치를 설정하여 발생합니다. 이렇게하면 화면 밖에서 아무 것도 누르지 않고 가능한 한 뷰를 동적으로 늘릴 수 있습니다.

+0

멋진 답변을 주셔서 감사합니다. – Boardy

0

중간 및 아래쪽 요소에 대해 android:layout_height="match_parent" (동일 "fill_parent")을 정의 했으므로 문제가 발생합니다. 위에서 아래로 레이아웃하면 사용 가능한 모든 공간이 스크롤보기에 제공됩니다. android:layout_weight 매개 변수를 살펴 보거나 구체적으로 layout_height을 설정할 수 있습니다. 15dp 또는 그와 비슷한 것들이지만, 절대 값은 안드로이드에서 좋지 않습니다 (다른 모든 화면 크기와 해상도로 인해).

관련 문제