2014-03-28 1 views
0

프로파일 페이지에 textviews와 imageviews 및 listview가있는 linearlayout이 있습니다. 내가 대신 단지 목록보기의 트위터 응용 프로그램처럼 전체 페이지를 스크롤 가능하게하려는안드로이드리스트 뷰 스크롤 할 수 없음

enter image description here

문제는 (그림 참조). 따라서 listview는 최대 높이까지 확장해야합니다.

어떻게 목록 뷰를 최대 크기까지 확장하고 스크롤 할 수 없게 할 수 있습니까?

linearlayout은 두 번째 옵션이 될 수 있지만 listview와 같은 사용자 정의 행이있는 사용자 정의 배열 어댑터를 추가 할 수 있어야합니다.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/scrollview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:fillViewport="true"> 

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

    ...... 
</LinearLayout 
</ScrollView> 

가있는 ScrollView는 하나의 아이에 소요 유의 사항 :

+0

당신은 또한 – krishna

+1

를 코드를 게시 할 수있는 링크가 내 대답을 확인할 수 있습니다 지금까지 내가 당신이 수직의 ListView를 사용하여 이해. 선형 레이아웃을 Header of Listview에 추가하면 모든 페이지를 스크롤 할 수 있습니다. – anber

답변

8

당신은 두 가지 방법으로 만들 수 있습니다

# Header을 추가 한 당신의 Listview

View header = inflater.inflate(R.layout.your_header_layout, null); 
    yourlistview.addHeader(header); 

# 2 당신은 children.Call에 따라 목록보기 높이를 설정할 수 있습니다 목록보기이 fxn 및 모든 위젯을 scrollview에 보관하십시오.

public static void setListViewHeightBasedOnChildren(ListView listView) { 

    ListAdapter listAdapter = listView.getAdapter(); 
    if (listAdapter == null) { 
     return; 
    } 

    int totalHeight = 0; 
    for (int i = 0, len = listAdapter.getCount(); i < len; i++) { 
     View listItem = listAdapter.getView(i, null, listView); 
     listItem.measure(0, 0); 
     totalHeight += listItem.getMeasuredHeight(); 
    } 

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

두 번째 함수를 사용하여 listview를 maxheight에 너무 강제합니다. 도움을 주셔서 감사합니다! – kevingoos

0

사용있는 ScrollView는 레이아웃을 포장합니다. 따라서 원래 레이아웃을 적절하게 조정하십시오.

1

예 스크롤보기를 부모보기로 설정하고 목록보기에 대한 사용자 정의 클래스를 만들 수 있습니다. 당신은

list view in scroll view

관련 문제