2013-07-20 4 views
0

두 목록보기를 사용하고 있습니다. 올바르게 보이지만 두 번째 목록보기가 가로 모드로 표시되지 않습니다. listview에서 scrollview를 사용할 수 없습니다.스크롤 목록보기 android

내 레이아웃 파일 :

나는 하나의 스크롤에 두 개의 목록보기를 먹고 싶어
<?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="wrap_content" 
    android:background="#E9E0DB" 
    android:orientation="horizontal" 
    android:padding="5dp" > 

    <LinearLayout 
     android:id="@+id/thumbnail" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginRight="5dip" 
     android:orientation="vertical" 
     android:padding="3dp" > 

     <ImageView 
      android:id="@+id/list_image" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/member_80" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/thumbnail" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:text="Hermoine" 
     android:textColor="#040404" 
     android:textSize="16dp" 
     android:textStyle="normal" 
     android:typeface="sans" /> 

    <TextView 
     android:id="@+id/usertype" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/username" 
     android:layout_marginTop="1dip" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:text="Basic" 
     android:textColor="#343434" 
     android:textSize="12dp" /> 

    <TextView 
     android:id="@+id/joined_on" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/usertype" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:text="Joined on Sep,21 2013" 
     android:textColor="#343434" 
     android:textSize="12dp" /> 

    <TextView 
     android:id="@+id/total_posts" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/usertype" 
     android:layout_gravity="center_vertical" 
     android:layout_weight="1" 
     android:scaleType="fitEnd" 
     android:text="899 Posts" 
     android:textSize="12dp" /> 

    <TextView 
     android:id="@+id/membervotes" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_weight="1" 
     android:background="@drawable/votes_bg" 
     android:text="388" 
     android:textColor="#343434" 
     android:textSize="10dp" /> 

    <View 
     android:id="@+id/topformline" 
     android:layout_width="fill_parent" 
     android:layout_height="0.5dp" 
     android:layout_below="@+id/thumbnail" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="6dp" 
     android:background="@android:color/darker_gray" 
     android:gravity="center" /> 

    <LinearLayout 
     android:id="@+id/btnsettings" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/topformline" 
     android:orientation="horizontal" 
     android:weightSum="3" > 

     <Button 
      android:id="@+id/btnNotification" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:layout_marginTop="2dp" 
      android:layout_weight="1" 
      android:background="@android:color/transparent" 
      android:drawableTop="@drawable/notification_icon" /> 

     <View 
      android:layout_width="0.8dp" 
      android:layout_height="25dp" 
      android:layout_marginTop="8dp" 
      android:background="@android:color/darker_gray" /> 

     <Button 
      android:id="@+id/btnMsg" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:layout_weight="1" 
      android:background="@android:color/transparent" 
      android:drawableTop="@drawable/messages_icon" /> 

     <View 
      android:layout_width="0.8dp" 
      android:layout_height="25dp" 
      android:layout_marginTop="8dp" 
      android:background="@android:color/darker_gray" /> 

     <Button 
      android:id="@+id/btnprofile_settings" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="2dp" 
      android:layout_weight="1" 
      android:background="@android:color/transparent" 
      android:drawableTop="@drawable/setting_icon" /> 
    </LinearLayout> 

    <View 
     android:id="@+id/bottomformline" 
     android:layout_width="fill_parent" 
     android:layout_height="0.5dp" 
     android:layout_below="@+id/btnsettings" 
     android:layout_marginTop="-15dp" 
     android:background="@android:color/darker_gray" 
     android:gravity="center" /> 


       <ListView 
       android:id="@+id/list_view" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/bottomformline" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginTop="20dp" 
       android:background="#FFFFFF" /> 

      <ListView 
       android:id="@+id/follow_list_view" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/list_view" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginTop="10dp" 
       android:background="#FFFFFF" /> 

</RelativeLayout> 

. 그렇게하는 방법? 어떤 제안을 해주시겠습니까?

감사, 세로 및 가로보기의

+0

후 스크린 샷. –

답변

1
You can put these two listview in scroll view, and disable the scrolling of listviews, Now you will have single scrollview for two listviews. 

    <ScrollView 
     android:id="@+id/bottomformline" 
     android:layout_width="fill_parent" > 


      <your.package.name.NestedListView 
       android:id="@+id/list_view" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#FFFFFF" /> 

      <your.package.name.NestedListView 
       android:id="@+id/follow_list_view" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#FFFFFF" /> 
</ScrollView> 

    public class NestedListView extends ListView implements OnTouchListener, OnScrollListener { 

     private int listViewTouchAction; 
     private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 99; 

     public NestedListView(Context context, AttributeSet attrs) { 
      super(context, attrs); 
      listViewTouchAction = -1; 
      setOnScrollListener(this); 
      setOnTouchListener(this); 
     } 

     @Override 
     public void onScroll(AbsListView view, int firstVisibleItem, 
       int visibleItemCount, int totalItemCount) { 
      if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) { 
       if (listViewTouchAction == MotionEvent.ACTION_MOVE) { 
        scrollBy(0, -1); 
       } 
      } 
     } 

     @Override 
     public void onScrollStateChanged(AbsListView view, int scrollState) { 
     } 

     @Override 
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
      super.onMeasure(widthMeasureSpec, heightMeasureSpec); 

      int newHeight = 0; 
      final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 
      int heightSize = MeasureSpec.getSize(heightMeasureSpec); 
      if (heightMode != MeasureSpec.EXACTLY) { 
       ListAdapter listAdapter = getAdapter(); 
       if (listAdapter != null && !listAdapter.isEmpty()) { 
        int listPosition = 0; 
        for (listPosition = 0; listPosition < listAdapter.getCount() 
          && listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) { 
         View listItem = listAdapter.getView(listPosition, null, this); 
         //now it will not throw a NPE if listItem is a ViewGroup instance 
         if (listItem instanceof ViewGroup){ 
          listItem.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
         } 
         listItem.measure(widthMeasureSpec, heightMeasureSpec); 
         newHeight += listItem.getMeasuredHeight(); 
        } 
        newHeight += getDividerHeight() * listPosition; 
       } 
       if ((heightMode == MeasureSpec.AT_MOST) && (newHeight > heightSize)) { 
        if (newHeight > heightSize) { 
         newHeight = heightSize; 
        } 
       } 
      } else { 
       newHeight = getMeasuredHeight(); 
      } 
      setMeasuredDimension(getMeasuredWidth(), newHeight); 
     } 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) { 
       if (listViewTouchAction == MotionEvent.ACTION_MOVE) { 
        scrollBy(0, 1); 
       } 
      } 
      return false; 
     } 
    }