2013-11-28 3 views
0

장치의 buttom에 레이아웃 버튼을 배치하려고합니다. PIC1에 따라레이아웃을 선언하여 여러 장치에서 ListView의 높이를 자동으로 조정하는 방법은 무엇입니까?

4.0 인치 장치에 배치하고, PIC2는 4.7 인치 장치

에 있으며 XML 코드가 시도됩니다.

버튼이 4.0 인치, 에서 올바른 위치에 배치되었지만 4.7 인치에 배치되지 않았습니다.

목록보기의 높이를 자동으로 조정하고 싶습니다.

어떻게 수행하나요?


[PIC1]

enter image description here


[PIC2]

enter image description here


여기서 XML 코드이다.

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

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

    <TextView 
      android:id="@+id/txtLabel2" 
      android:text="Buyed items" 
      android:textSize="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

    <ListView 
      android:id="@+id/lsv_buyedList" 
      android:layout_width="match_parent" 
      android:layout_height="450dp"> 
    </ListView> 


    <LinearLayout 
      android:gravity="center_vertical" 
      android:orientation="horizontal" 
      android:layout_marginTop="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     <LinearLayout 
       android:layout_weight="1" 
       android:layout_marginLeft="10dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      <Button 
        android:id="@+id/btn_sortById" 
        android:text="SortById" 
        android:textSize="15dp" 
        android:layout_width="110dp" 
        android:layout_height="wrap_content"/> 

      <Button 
        android:id="@+id/btn_sortByGrade" 
        android:text="SortByGrade" 
        android:textSize="15dp" 
        android:layout_width="110dp" 
        android:layout_height="wrap_content"/> 
     </LinearLayout> 

     <Button 
       android:id="@+id/btn_confirm" 
       android:text="OK" 
       android:textSize="15dp" 
       android:layout_width="100dp" 
       android:layout_marginRight="10dp" 
       android:layout_height="wrap_content"/> 

    </LinearLayout> 

</LinearLayout> 

답변

0

// 당신의 목록보기 android:layout_height="450dp"

에서 하드 코드 된 값을 제거하고

  <ListView 
       android:id="@+id/lsv_buyedList" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" > 
     </ListView> 
+0

감사를 android:layout_height="450dp"를 교체합니다. : D –

+1

이것이 맞습니다. –

+0

허용되는 대답에 따라 LinearLayout을 사용하지 말라는 조언이 없습니다. RelativeLayout을 사용하십시오. 그런 다음 Button 섹션에 사용 된 2 개의 LinearLayouts가 없어도 동일한 결과를 얻을 수 있습니다. 각 추가 레이아웃은 하나의 렌더링주기를 강제합니다. 여기서하는 일은 전혀 성과가 없습니다. – Baschi

1

리스트 뷰

android:layout_height="0dip" 
android:layout_weight="1" 
0

은 "무게"필드를 사용하여 목록보기 위해 무게를 사용 이 코드를 복사하여 붙여 넣으십시오 .. 제 컴퓨터에서 해보니 ... 즐기십시오!!

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

<TextView 
    android:id="@+id/txtLabel2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Buyed items" 
    android:textSize="20dp" /> 

<ListView 
    android:id="@+id/lsv_buyedList" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 

</ListView> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_weight="1" > 

     <Button 
      android:id="@+id/btn_sortById" 
      android:layout_width="110dp" 
      android:layout_height="wrap_content" 
      android:text="SortById" 
      android:textSize="15dp" /> 

     <Button 
      android:id="@+id/btn_sortByGrade" 
      android:layout_width="110dp" 
      android:layout_height="wrap_content" 
      android:text="SortByGrade" 
      android:textSize="15dp" /> 
    </LinearLayout> 

    <Button 
     android:id="@+id/btn_confirm" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="10dp" 
     android:text="OK" 
     android:textSize="15dp" /> 
</LinearLayout> 

</LinearLayout> 
1

목록보기에서 android:layout_height="wrap_conent"로 답변

관련 문제