2015-04-28 85 views
0

拉刷新列表視圖(拉)滾動視圖中不工作.. 它不滾動..拉刷新列表視圖滾動視圖內

這裏是我的xml文件。

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:orientation="horizontal" 
      android:padding="10dp" 
      android:background="#fff"> 

      <ImageView 
       android:id="@+id/profile_image" 
       android:layout_width="40dp" 
       android:layout_height="40dp" 
       android:scaleType="fitXY" 
       android:src="@drawable/loading_image" /> 

      <TextView 
       android:id="@+id/user_name" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:paddingLeft="10dp" 
       android:text="testcase1" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:scaleType="fitXY" 
       android:src="@drawable/clock_icon" /> 

      <TextView 
       android:id="@+id/time" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="1 day(s)ago" 
       android:textColor="@color/Gray" /> 
     </LinearLayout> 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:src="@drawable/loading_image_large" 
      android:scaleType="fitXY"/> 

     <TextView 
      android:id="@+id/likes" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableLeft="@drawable/clap" 
      android:drawablePadding="10dp" 
      android:padding="10dp" 
      android:text="1 like(s)" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="10dp" 
      android:text="view all comments" 
      android:textColor="@color/Gray" /> 




     <com.handmark.pulltorefresh.library.PullToRefreshListView 
      android:id="@+id/comments_listview" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" /> 
     <EditText 
      android:id="@+id/comment_editText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:layout_marginRight="5dp" 
      android:background="@drawable/gray_stroke_sec" 
      android:hint="New Comment" 
      android:inputType="textCapSentences|textMultiLine" 
      android:maxLines="3" 
      android:minHeight="40dp" 
      android:padding="10dp" 
      android:scrollHorizontally="true" 
      android:textSize="@dimen/text_size_14" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" > 

      <ImageView 
       android:id="@+id/like_image" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:src="@drawable/like" /> 

      <ImageView 
       android:id="@+id/repost" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:src="@drawable/repost" /> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="4" 
       android:gravity="right|center_vertical" > 

       <TextView 
        android:id="@+id/comment" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/comment_bg" 
        android:gravity="center" 
        android:padding="10dp" 
        android:text="Comment" 
        android:textColor="#fff" 
        android:textSize="16sp" 
        android:clickable="true" 
        android:textStyle="bold" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
+0

它有自己的滾動功能。無需放入滾動視圖。 – Piyush

+0

我有更多的數據顯示在同一屏幕上..... –

+0

然後,如果你堅持把你的listview在scrollview中,然後把你的listview在片段視圖。 – Elltz

回答

0

那麼顯然不應該做你願意do.Ite不推薦 但你仍然可以把你的LinearLayout PullToRefreshView,如果你想要的工作

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

    <com.handmark.pulltorefresh.library.PullToRefreshListView 
     android:id="@+id/comments_listview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" /> 

</LinearLayout> 

還是想讓什麼你知道,這不是建議。

+0

其不能正常工作 –

+0

請查看[link](http://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view)獲取更多幫助 –

0

這是使用Android支持SwipeRefreshLayout代替。

http://nlopez.io/swiperefreshlayout-with-listview-done-right/

<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/swipe_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="@string/guides_no_results" 
      android:id="@+id/empty_view" 
      android:gravity="center" 
      android:padding="16dp" 
      android:fontFamily="sans-serif-light" 
      android:textSize="20sp" 
      android:visibility="gone"/> 


     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:drawSelectorOnTop="true" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="0dp" 
      android:id="@+id/guides_list" /> 

    </LinearLayout> 

</android.support.v4.widget.SwipeRefreshLayout> 

,然後在代碼:

guidesList.setOnScrollListener(new AbsListView.OnScrollListener() { 
    @Override 
    public void onScrollStateChanged(AbsListView view, int scrollState) { 

    } 

    @Override 
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 
     int topRowVerticalPosition = 
      (guidesList == null || guidesList.getChildCount() == 0) ? 0 : guidesList.getChildAt(0).getTop(); 
     swipeContainer.setEnabled(firstVisibleItem == 0 && topRowVerticalPosition >= 0); 
    } 
});