2013-04-22 25 views
2
正常工作

我使用拉,刷新滚动视图工具与此库的帮助拉刷新自动滚动不能在Android的

https://github.com/chrisbanes/Android-PullToRefresh

这是工作非常精细的,而不是scrollTo(int,int);方法 我在代码下面我在最后添加列表中的所有项目后使用此方法。

代码在这里。

public class MainActivity extends Activity { 
PullToRefreshScrollView mPullRefreshScrollView; 
LinearLayout listHolder; 
ArrayList<String> list = new ArrayList<String>(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    listHolder = (LinearLayout) findViewById(R.id.lay); 

    // initial values in List 
    for(int i =0;i<15;i++){ 
     list.add("InitialValue"); 
    } 

    mPullRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pull_refresh_scrollview); 
    mPullRefreshScrollView 
      .setOnRefreshListener(new OnRefreshListener<ScrollView>() { 

       @Override 
       public void onRefresh(
         PullToRefreshBase<ScrollView> refreshView) { 
        new GetDataTask().execute(); 
       } 
      }); 

    addJournal_Entry_page(); 
} 

private class GetDataTask extends AsyncTask<Void, Void, String[]> { 
    @Override 
    protected String[] doInBackground(Void... params) { 
     try { 
      Thread.sleep(2000); 
      for(int i =0;i<4;i++){ 
       list.add("InitialValue"); 
      } 
     } catch (InterruptedException e) { 
     } 
     return null; 
    } 

    @Override 
    protected void onPostExecute(String[] result) { 
     // Do some stuff here 

     // Call onRefreshComplete when the list has been refreshed. 
     mPullRefreshScrollView.onRefreshComplete(); 
     addJournal_Entry_page(); 
     super.onPostExecute(result); 
    } 
} 

private void addJournal_Entry_page() { 

    View v; 
    listHolder.removeAllViews(); 
    for (int i = 0; i < list.size(); i++) { 
     v = this.getLayoutInflater().inflate(R.layout.list_row, null); 
     TextView ind = (TextView)v.findViewById(R.id.index); 
     TextView name = (TextView)v.findViewById(R.id.name); 

     ind.setText(""+i); 
     name.setText(list.get(i)); 

     listHolder.addView(v); 
    } 

    Resources r = getResources(); 
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
      100, r.getDisplayMetrics()); 

    //problem is Here 
    mPullRefreshScrollView.scrollTo(0,(int)px); 

} 

} 

我在XML定义PullToRefreshScrollView这样

<com.handmark.pulltorefresh.library.PullToRefreshScrollView 
    xmlns:ptr="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/pull_refresh_scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    ptr:ptrAnimationStyle="flip" 
    ptr:ptrMode="pullFromStart" > 

    <LinearLayout 
     android:id="@+id/lay" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 
    </LinearLayout> 
</com.handmark.pulltorefresh.library.PullToRefreshScrollView> 

我得到的结果是这样

enter image description here

有我的列表中15项所以它不应该显示空白在列表的底部。

非常感谢

+1

对你有什么好运我有同样的问题 – 2014-06-06 07:16:48

回答

1

请将此代码添加下在PullToRefreshScrollView.java此行

最后一类InternalScrollViewSDK9扩展滚动型{

@Override 
     public void scrollTo(int x, int y) { 
      // TODO Auto-generated method stub 
      super.scrollTo(x, y); 
     } 

}

在此输入代码。这个对我有用。