2015-01-23 2 views
0

두 개의 ListView가 서로 아래에있는 앱을 만들기 시작했습니다.모든 항목을 Android의 ListView에 표시합니다.

itmes가 너무 커질 수 있으므로 전체 레이아웃을 스크롤 할 수 있고 목록 자체가 없기 때문에 ScrollView를 위에 추가했습니다. 하지만 내 솔루션 dosent 작동!

btw : 내 모든 어댑터가 없어져서 ListView를 LinearLayout으로 바꾸고 싶지 않습니다.

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

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

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

      <TextView 
       style="@style/Heading" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="ListView1" /> 

      <Space 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       style="@style/ButtonStyle.SpinnerAddButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:drawableRight="@drawable/ic_add_black_24dp" 
       android:onClick="addToList1" /> 

     </LinearLayout> 

     <ListView 
      android:id="@+id/listView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/marginLeft" 
      android:layout_marginRight="@dimen/marginLeft" /> 


    <!--Second list--> 

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

      <TextView 
       style="@style/Heading" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="ListView2" /> 

      <Space 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       style="@style/ButtonStyle.SpinnerAddButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:drawableRight="@drawable/ic_add_black_24dp" 
       android:onClick="addToList2" /> 

     </LinearLayout> 

     <ListView 
      android:id="@+id/listView2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/marginLeft" 
      android:layout_marginRight="@dimen/marginLeft" /> 

    </LinearLayout> 
</ScrollView> 

이제 내 레이아웃은 모든 ListView를 서로간에 표시하지만 ListView 당 하나의 항목 만 표시하므로이 목록을 스크롤 할 수 있습니다.

+1

'ScrollView'에서 수직 스크롤 가능 물건을 넣는 것은 어렵습니다. ViewPager에서 두 페이지를 사용하는 것과 같이 각 목록 + 버튼 쌍마다 하나씩 다른 UI를 제안하는 것이 좋습니다. – CommonsWare

+1

'ScrollView' +'ListView' +'ListView' = 나쁜 일이 일어날 것입니다. – Simas

+0

다른 스크롤 가능한 스크롤 기능은 실제로 ** 최악의 디자인 ** UI입니다. –

답변

0

하나의 목록보기를 사용해야하며 다른보기 유형 만 사용해야합니다.

@Override 
public int getItemViewType(int position) { 
    return isFirstItem(position) ? TYPE_ITEMA : TYPE_ITEMB; 
} 

@Override 
public int getViewTypeCount() { 
    return 2; 
} 
관련 문제