2013-03-27 5 views
0

나는 아주 간단한 것을하고 싶습니다. 상단에 회 전자가있는 레이아웃이 필요하고, 목록보기가 뒤따라오고, 맨 아래에는 선형 버튼이 몇 개 배치되어 있습니다. 윈도우가 얼마나 큰 지 상관없이리스트 뷰가 스피너와 버튼 사이의 공간을 채우기 위해 확장되기를 원합니다. 나는이 세 가지 요소를 래핑하는 선형 레이아웃으로 시도하고 Layout_Height에 대해 Wrap Content 및 Fill Parent의 모든 조합을 시도했지만 목록보기 Layout_Height를 하드 코딩하지 않으면 300 개의 딥이 표시되고 단추는 밀려납니다. 화면에서. 나는 이것을 할 수있는 쉬운 방법이 있어야한다는 것을 압니다. 그러나 나는 지혜로 끝납니다. 나는 내가 생각할 수있는 모든 것을 시도했다.간단한 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="fill_parent" 
android:orientation="vertical" > 

<Spinner 
    android:id="@+id/fileType" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

<ListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="300dip" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="bottom" 
    android:gravity="bottom" 
    android:orientation="vertical" > 

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

     <Button 
      android:id="@+id/ManageFiles_DeleteItem" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="5dip" 
      android:layout_weight="1" 
      android:text="Delete item" /> 

     <Button 
      android:id="@+id/ManageFiles_DeleteAll" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="5dip" 
      android:layout_weight="1" 
      android:text="Delete all" /> 

     <Button 
      android:id="@+id/ManageFiles_DisplayItem" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="5dip" 
      android:layout_weight="1" 
      android:text="Display item" /> 
    </LinearLayout> 

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

     <Button 
      android:id="@+id/ManageFiles_OKcustom" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="10dip" 
      android:layout_weight="1" 
      android:text="OK" /> 

     <Button 
      android:id="@+id/ManageFiles_CancelCustom" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="10dip" 
      android:layout_weight="1" 
      android:text="Cancel" /> 
    </LinearLayout> 
</LinearLayout> 

`

+0

어떤 장치의 총 높이이며 프레임 워크의 어떤 종류의 당신이 생각하고, –

+0

@Arju의 LinearLayout, 각 회 전자, 목록보기 무엇 높이를 필요합니까? Android 기기를 정말로 생각하십니까? –

답변

0

사용하여 다음

android:weightSum="Your total length" //in your main layout 

android:layout_weight="" //in each of your listview,spinner,linearlayout 

예 : u는 3 개 요소

Spinner 
android:layout_weight="1" 
/> 

ListView 
android:layout_weight="1" 
/> 

LinearLayout 
android:layout_weight="1" 
/> 

android:weightSum="3" 

다음 사용을 위해 동일한 공간을 필요로하는 경우 0

0

무게를 사용하여 목록보기에 2의 무게를주고, 각각을 회 전자에 1 개 배치하고 아래쪽에 버튼이있는 레이아웃으로 무게를 바꿀 수 있습니다.

+0

이것은 전혀 작동하지 않는 것 같습니다. 목록에 데이터가 채워지면 위쪽으로 떠 있었고 키가 크지 않았습니다. 그리고 하단의 단추 레이아웃이 화면에서 절반 쯤 떨어졌습니다. 왜 이렇게 힘들지? ??? – Don

+0

한 가지 중요한 정보를 알려주는 것을 잊었습니다! 이 작업을 수행하려면 세 요소 모두의 layout_height를 0px로 설정해야합니다. 이제 작동합니다! – Don

+0

나중에 당신은 그것을 할 필요가 실제로 레이아웃을 게시하고 그것을 다시 게시하려고했지만 stackoverflow 편집기와 함께 몇 가지 formating 문제가 그래서 다시 게시 할 수 없습니다 – user2041902

1

당신은 트릭이 RelativeLayout의 대신에있는 LinearLayout을 사용하는 것입니다

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<Spinner 
    android:id="@+id/spinner1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" /> 

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/spinner1" 
    android:layout_above="@+id/button1" > 
</ListView> 

<Button 
    android:id="@id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:text="Button1" /> 

<Button 
    android:id="@id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="Button2" /> 

로 간단하게 뭔가를 시도 할 수 있습니다.

+0

고마워, 난 상대 레이아웃에 대해 몰랐어요 . 다른 제안에 따라 layout_weight를 사용했는데 문제가 해결되었지만 이제 상대 레이아웃을 시도해보고 작동하는지 확인한 다음 내 레퍼토리에 표시 할 것입니다. – Don

0

이렇게하면 모든 화면 크기에 맞을 수 있습니다.

<?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" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/ftr_btn" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:gravity="bottom" 
    android:orientation="vertical" > 

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

     <Button 
      android:id="@+id/ManageFiles_DeleteItem" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="5dip" 
      android:layout_weight="1" 
      android:text="Delete item" /> 

     <Button 
      android:id="@+id/ManageFiles_DeleteAll" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="5dip" 
      android:layout_weight="1" 
      android:text="Delete all" /> 

     <Button 
      android:id="@+id/ManageFiles_DisplayItem" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="5dip" 
      android:layout_weight="1" 
      android:text="Display item" /> 
    </LinearLayout> 

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

     <Button 
      android:id="@+id/ManageFiles_OKcustom" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="10dip" 
      android:layout_weight="1" 
      android:text="OK" /> 

     <Button 
      android:id="@+id/ManageFiles_CancelCustom" 
      android:layout_width="fill_parent" 
      android:layout_height="40dip" 
      android:layout_margin="10dip" 
      android:layout_weight="1" 
      android:text="Cancel" /> 
    </LinearLayout> 
</LinearLayout> 

<Spinner 
    android:id="@+id/fileType" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" /> 

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/ftr_btn" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/fileType" > 
</ListView> 

+0

이것이 내가 찾던 해결책이다. 그것은 완벽하게 작동합니다. 고맙습니다. – Don

+0

@Don 언제든지 환영합니다. – Yugesh