2017-02-25 261 views
0

我正在使用ScrollView查看文件。問題是,當我滾動時,它很粘,不太光滑。我找到了一個非常流暢的警告對話框代碼。有什麼辦法讓ScrollView上的滾動像alert對話框一樣嗎?怎麼樣?滾動視圖的平滑滾動

下面是滾動型實現的例子:

公共無效buttonLoad(查看視圖){

File file = new File(path + "/savedFile.txt"); 
    String [] loadText = Load(file); 

    String finalString = ""; 

    for(int i = 0; i<loadText.length; i++) 
    { 
     finalString += loadText[i] + System.getProperty("line.separator"); 
    } 

    //textView.setText(finalString); 
    //textView.setMovementMethod(new ScrollingMovementMethod()); 

    textView.setMovementMethod(new ScrollingMovementMethod()); 
    textView.setText(finalString); 

    /*String title = "title"; 
    String Message = finalString; 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setCancelable(true); 
    builder.setTitle(title); 
    builder.setMessage(Message); 
    builder.show();*/ 
} 
+0

什麼對話框?你的榜樣在哪裏? –

+0

@ cricket_007這是我的第一個查詢。我試圖發佈一些代碼,但似乎太長。你能幫我嗎? –

+0

試着創建你的代碼的[mcve],並且你可以鏈接到示例對話框。 [編輯]相應 –

回答

0

使用RecyclerView。這個滾動視圖比平常快。

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/recyclerSelectGame" 
    > 
</android.support.v7.widget.RecyclerView> 
+0

https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html –