2015-01-30 2 views
0

scrollview 및 gridlayout을 사용하고 있습니다. 결과에는 autocompleteTextview, 1 버튼 및 listview가 있습니다.Listview 마지막 항목 가시성 goin out of screen

`

<GridLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="1" > 

    <AutoCompleteTextView 
     android:id="@+id/AutoText_dest" 
     android:layout_column="0" 
     android:layout_gravity="left|top" 
     android:layout_row="0" 
     android:ems="10" 
     android:hint="Desired Destination" 
     android:imeOptions="actionDone" 
     android:singleLine="true" > 

     <requestFocus /> 
    </AutoCompleteTextView> 

    <Button 
     android:id="@+id/btn_load_directions" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_column="0" 
     android:layout_gravity="right|top" 
     android:layout_row="0" 
     android:background="@drawable/ic_action_search" 
     /> 

    <ListView 
     android:id="@+id/Listview_search_results" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:layout_gravity="fill_vertical" 
     android:layout_marginTop="10dp" 
     android:layout_row="1" > 

    </ListView> 

</GridLayout> 

`

레이아웃을 수정하기위한 몇 가지 조언이 필요 다음과 같이 그러나 목록보기의 마지막 항목이

enter image description here

내 XML 코드와 같은 화면에서가는 있습니다 것은 . 고맙습니다.

편집이 : 나는 단지 제거있는 ScrollView 및 실행 프로젝트 ...하지만 여전히 문제가 지속 .. 출력은 당신이 볼 수있는이

enter image description here

처럼, 목록보기의 마지막 항목은 절반 또는 1/3이다 표시됩니다. 그 결과로 DB 작업을 건너 뛸 수 없습니다.

+0

나는 그것을 잘 해킹했습니다. 내가 그것을 파 내면 나는 그것을 게시 할 것이다. –

+1

나는 신이 맹세코 주변에 다니고 모든 안드로이드 질문을 정기적으로 하향식하는 사람이 있다고 단언한다. –

+0

ListView의 뷰 수가 고정되면 ListView 대신 LinearLayout을 수직으로 사용한다. – Hemanth

답변

1

인터넷에서이 유틸리티 클래스를 발견했으며 누가 작성했는지 다시 기억할 수 없습니다. 원본 소스를 찾을 수 있으면 특성을 제공합니다. 나는 그것을 조금 수정했다.

public class Utility { 
    public static void setListViewHeightBasedOnChildren(ListView listView) { 
     ListAdapter listAdapter = listView.getAdapter(); 
     if (listAdapter == null) { 
      // pre-condition 
      return; 
     } 

     int totalHeight = 0; 
     int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST); 
     for (int i = 0; i < listAdapter.getCount(); i++) { 
      View listItem = listAdapter.getView(i, null, listView); 
      listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); 
      totalHeight += listItem.getMeasuredHeight(); 
     } 
     //I added this to try to fix half hidden row 
     totalHeight++; 

     ViewGroup.LayoutParams params = listView.getLayoutParams(); 
     params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
     listView.setLayoutParams(params); 
     listView.requestLayout(); 
    } 
} 

이 클래스를 구현하는 방법.

ListView lv; 
ArrayAdapter adapter; 
.... 
lv.setAdapter(adapter); 
//set height to see all items - hack because of listview in scrollable view 
Utility.setListViewHeightBasedOnChildren(lv); 

는 XML :

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

    <ScrollView 
    .... 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true"> 

     <LinearLayout 
     .... 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"> 
      <ListView 
      .... 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"></ListView> 

     </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 
+0

buddy..jst 내가 원했던 .. ..thanx .. – SK16

+0

Excellent :) 나는 우리 모두가 같은 투쟁에 직면하고 있음을 이해합니다. –

+0

이 코드를 코드와 정확하게 추가하면 더 이상 표시 할 데이터가 없어도 내 목록 뷰가 내부적으로 스크롤되므로 화면이 비어있게됩니다. 유틸리티 방법에 몇 가지 구성을 써야한다고 생각합니다. 맞습니까? 추신 내 XML 레이아웃에도 바닥 글 레이아웃이 포함되어 있습니다. 이것이 높이 계산에 영향을 줍니까? –

1

가 대신 그리드 레이아웃을 사용하는 u는 상대 레이아웃을 사용할 수 있습니다. 아래 코드로 시도하십시오.

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

<AutoCompleteTextView 
    android:id="@+id/AutoText_dest" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:hint="Desired Destination" 
    android:imeOptions="actionDone" 
    android:singleLine="true" > 

    <requestFocus /> 
</AutoCompleteTextView> 

<Button 
    android:id="@+id/btn_load_directions" 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:background="@drawable/ic_launcher" /> 

<ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/AutoText_dest" 
    android:layout_marginTop="10dp" > 
</ListView> 

</RelativeLayout>