2017-05-16 7 views
0

navigation openウェブビューで開いている別のウェブサイトを開くが、私がウォルマートウェブサイトを開いているときに私はウェブサイトのナビゲーションバー一番上に行かないのは、それをリフレッシュするためのスクロールです。 Scroll for going on top of navigation top but not scroll going swipe to refreshアンドロイドウェブビュースワイプウェブサイトのナビゲーションバーでリフレッシュするスクロールダウン問題

私のxmlファイルは次のとおりです。 -

`<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/swipeContainer" 
    android:layout_width="match_parent" 
    android:layout_below="@+id/progressBar" 
    android:layout_height= "match_parent"> 


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

私のJavaコードは次のとおりです。 - 事前にあなたに感謝 悪い英語のため申し訳ありません

public class MainActivity extends AppCompatActivity { 
private WebView myWebView; 
Context context; 
Toolbar toolbar; 
ProgressBar progressBar; 
SwipeRefreshLayout mySwipeRefreshLayout; 
WebSettings settings; 

RelativeLayout relativeLayout; 

@SuppressLint("SetJavaScriptEnabled") 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    myWebView = (WebView) findViewById(R.id.webView1); 
    myWebView.setWebViewClient(new WebViewClientDemo()); 
    myWebView.setWebChromeClient(new WebChromeClientDemo()); 
    myWebView.getSettings().setJavaScriptEnabled(true); 
    myWebView.loadUrl("https://www.walmart.com/"); 
    myWebView.getSettings().setDomStorageEnabled(true); 
    mySwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipeContainer); 

    mySwipeRefreshLayout.setOnRefreshListener(
      new SwipeRefreshLayout.OnRefreshListener() { 
       @Override 
       public void onRefresh() { 
        myWebView.reload(); 
       } 
      } 
    ); 

    mySwipeRefreshLayout.setNestedScrollingEnabled(false); 

答えて

0

ステップ1:スクロール位置が完全にスワイプされた場合、つまりy位置がゼロの場合は、スクロール位置を確認する必要があります。

ステップ2:あなたはcanChileScrollUp()方法

これを使用することによってそれを行うことができますが、それは更新されませんfalseを返した場合、「canChildScrollUpは」リフレッシュたりしないように天候を検出する機能を持つカスタムrefreshlayoutです。

"canSwipeRefreshChildScrollUp"はあなたのロジックをアクティビティに書き込む場所です。

public class YourActivity implements CustomSwipeRefreshLayout.CanChildScrollUpCallback { 

private CustomSwipeRefreshLayout mRefreshLayout; 
private WebView mWebView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // after initialization 
    mRefreshLayout.setCanChildScrollUpCallback(this); 
} 

@Override 
public boolean canSwipeRefreshChildScrollUp() { 
    return mWebview.getScrollY() > 0; 
} 
} 

は、ネストされたスクロールを検出するために、ウル場合の使用カスタムWebViewの中やスクロール位置を検出し、スクロールが完全に、その後に行われた場合にのみ、あなたの活動の真の

public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { 

private CanChildScrollUpCallback mCanChildScrollUpCallback; 

public interface CanChildScrollUpCallback { 
    boolean canSwipeRefreshChildScrollUp(); 
} 

public void setCanChildScrollUpCallback(CanChildScrollUpCallback canChildScrollUpCallback) { 
    mCanChildScrollUpCallback = canChildScrollUpCallback; 
} 

@Override 
public boolean canChildScrollUp() { 
    if (mCanChildScrollUpCallback != null) { 
     return mCanChildScrollUpCallback.canSwipeRefreshChildScrollUp(); 
    } 
    return super.canChildScrollUp(); 
} 
} 

を返しますが、この

を使用することができます
public class MyWebView extends WebView{ 
@Override 
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { 
    if(clampedX || clampedY){ 
     //Content is not scrolling 
     //TODO Enable SwipeRefreshLayout 
    } 
} 
@Override 
public boolean onTouchEvent(MotionEvent event) { 
    if(event.getActionMasked()==MotionEvent.ACTION_UP){ 
     //TODO Disable SwipeRefreshLayout 
    } 
} 
} 
+0

ありがとうございましたXmlについて –

+0

xmlに変更が必要ありません –

+0

解説 –

関連する問題