2012-06-03 6 views
3

상단에 TextView, 중간에 ListView, 하단에 Button이있는 화면을 만들려고합니다. TextView이 항상 화면 상단에 있고 단추가 항상 맨 아래에 있고 그 다음에 ListView이 있어야합니다. ListView이 "중간의 공간"을 초과하면 스크롤 기능이 TextViewButton 사이에 있어야합니다. 내 시도로 그냥 TextViewButton 넘어 확장됩니다. (만 그렇지 않으면 ListView 아무것도 감아하는 데 사용할 경우) LinearLayout 제거해야 ListView 포장 (그리고 ListView 아래 /를 layout_above 이동)LinearLayout 내 ListView 배치하기

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/paper" > 

<TextView 
    android:id="@+id/tvLOL" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:text="Standardvarer" 
    android:textSize="40dp" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/tvLOL" 
    android:layout_alignBottom="@+id/bNyVare" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
</LinearLayout> 

<Button 
    android:id="@+id/bNyVare" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:text="Tilføj ny vare" 
    android:textSize="30dp" /> 

</RelativeLayout> 

답변

5

이 도움이된다면보기 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/paper" > 

<TextView 
    android:id="@+id/tvLOL" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:text="Standardvarer" 
    android:textSize="40dp" /> 

<Button 
    android:id="@+id/bNyVare" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:text="Tilføj ny vare" 
    android:textSize="30dp" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/tvLOL" 
    android:layout_above="@id/bNyVare" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

</RelativeLayout> 
+0

그것은 당신의 XML-정의의 하단에있는 ListView에와있는 LinearLayout을 넣어하는 것이 중요합니다. 그리고 나는 LinearLayout을 완전히 삭제하는 것을 고려할 것이다. – banzai86

3

@Luksprog에 대한 또 다른 해법은 분명히 더 복잡한 레이아웃을 만드는 길입니다. 나는 ListView을 둘러싸는 LinearLayout을 도랑질 할 것이지만, 뷰 계층에서 불필요한 복잡성을 제외하고는 아무것도 추가하지 않는다. 귀하의 질문에 설명 된대로

상대적으로 간단한 레이아웃을 동적으로 TextViewButton inbetween 모든 공간을 채우기 위해 루트로 LinearLayoutListView에 무게를 사용하여 작성 될 수있다. 이 무게는 또한 Button을 맨 아래로 끝까지 밀어 넣지 않고 밀어냅니다. 당신은/위 layout_below 자신의 id를 사용하려면 먼저 텍스트 뷰와 버튼을 정의하기 때문에

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:background="@drawable/paper" android:orientation="vertical"> 

    <TextView android:id="@+id/tvLOL" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_gravity="center_horizontal" 
     android:text="Standardvarer" android:textSize="40dp" /> 

    <ListView android:id="@android:id/list" android:layout_width="fill_parent" 
     android:layout_height="0dp" android:layout_weight="1" /> 

    <Button android:id="@+id/bNyVare" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="Tilføj ny vare" 
     android:textSize="30dp" /> 

</LinearLayout> 
관련 문제