2012-01-01 2 views
2

나는 listview 또는 tableview를 2/3 화면에 차지하고 싶습니다. 그러면리스트 뷰 바로 아래에 거대한 버튼이 생깁니다. 지금 문제는 listview가 화면의 전체 높이를 차지한다는 것입니다. 그래픽 레이아웃의 높이를 조정할 수 없었습니다. 나는 5 개의 항목 높이 크기를 취하고 싶습니다. 수직있는 LinearLayout 당신을 위해 잘 작동하는 것처럼 아래, 당신은 귀하의 질문에 말에서안드로이드 레이아웃리스트 뷰 높이 조정 relativelayout 아래

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/relativeLayout" 
    android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android"> 
<ListView android:layout_height="wrap_content" 
    android:id="@+id/listView1" 
    android:layout_width="fill_parent" android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true"></ListView> 

</RelativeLayout> 

답변

3

을 화면에 버튼 센터 것, 그것은 소리. ListView는 최상위 레벨 LinearLayout 안에 두 개의 뷰를 배치하고 화면의 뷰를 분산시키기 위해 가중치를 사용하여 화면의 정확히 2/3를 차지하게 할 수 있습니다. 예를 들어

:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 
    <ListView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="2" > 
    </ListView> 
    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" > 
     <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true"/> 
    </RelativeLayout> 
</LinearLayout> 
+0

안드로이드 : layout_alignParentBottom 속성은 버튼 아래에 숨겨진 몇 가지 목록 항목의 원인이 될 수 있습니다. – mvsagar

4
<?xml version="1.0" encoding="utf-8"?> 

    <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/relativeLayout" 
     android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android"> 

<ListView android:layout_height="fill_parent" 
     android:id="@+id/listView1" 
     android:layout_above="@+id/button1" 
     android:layout_width="fill_parent"></ListView> 

<Button android:layout_height="wrap_content" 
     android:id="@+id/button1" 
     android:layout_alignParentBottom="true" 
     android:layout_width="fill_parent"></Button > 

    </RelativeLayout> 
+0

+1은 RelativeLayout을 사용하여 보존합니다. – superjos

+0

이것은 나를 위해 일했습니다. 감사. 그러나, 안드로이드 : layout_above 이외에 android : layout_below 속성을 사용하여 목록 뷰가 내 앱의 다른 두보기 사이에 있는지 확인해야했습니다. – mvsagar