데이터가로드 된 후 scrollview가 webview로 스크롤되는 것을 방지하는 방법은 무엇입니까?
그래서 저는 흥미로운 문제가 있습니다. 수동 또는 프로그래밍 방식으로 뷰를 스크롤하지 않는다는 사실에도 불구하고 내 WebView는 내부 데이터가로드 된 후 자동으로 스크롤됩니다.
뷰 페이저에 조각이 있습니다. 호출기를 처음로드하면 예상대로 작동하고 모든 것이 표시됩니다. 그러나 일단 "페이지를 넘기면"데이터가로드되고 WebView가 페이지 상단에 팝업되어 그 위에보기가 숨겨지는 것은 바람직하지 않습니다.
아무도 이것을 방지하는 방법을 알고 있습니까?
내 레이아웃은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/article_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="2dp"
android:text="Some Title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/article_title"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/LL_Seperator"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/text"
android:orientation="horizontal" >
</LinearLayout>
<WebView
android:id="@+id/article_content"
android:layout_width="match_parent"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/article_link"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:text="View Full Article"
android:textColor="@color/article_title"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
나는 또한 어떤 것에 초점을 맞추지 않고있다. 기본적으로 WebView가로드 된 후 자동으로 스크롤되는 것처럼 보입니다. 이것을 어떻게 방지합니까?
You can simply add this to your LinearLayout: android:focusableInTouchMode="true". It works for me.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical" >
I had the same problem, after hours of trying several ideas, what finally worked for me was simply adding the descendantFocusability
attribute to the ScrollView's containing LinearLayout, with the value blockDescendants
. In your case:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
Haven't had the problem reoccur since :)
You should create new class extend ScrollView, then Override requestChildFocus:
public class MyScrollView extends ScrollView {
@Override
public void requestChildFocus(View child, View focused) {
if (focused instanceof WebView )
return;
super.requestChildFocus(child, focused);
}
}
Then in your xml layout, using:
<MyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
That works for me. The ScrollView will not auto scroll to the WebView anymore.
Adding these line in main layout solves the problem
android:descendantFocusability="blocksDescendants"
Like this:
<com.ya.test.view.MyScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true" >
Probably there are people who have the same problem I was having, so I'll help out.
I was trying to put android:descendantFocusability="beforeDescendants" in my main ScrollView as following:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants">
/*my linearlayout or whatever to hold the views */
and it wasn't working, so I had to make a RelativeLayout the parent of the ScrollView, and place the android:descendantFocusability="beforeDescendants" in the parent aswell.
So I solved it doing the following:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
/*my linearlayout or whatever to hold the views */
I had to use the fully qualified name for MyScrollView, otherwise I got an inflate exception.
<com.mypackagename.MyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
'Programming' 카테고리의 다른 글
초점에 주황색 윤곽선 강조 표시 비활성화 (0) | 2020.08.10 |
---|---|
멀티 기가 바이트 텍스트 파일을 편집하는 방법은 무엇입니까? (0) | 2020.08.10 |
AngularJS의 ng-src에 대한 이미지로드 이벤트 (0) | 2020.08.10 |
설치 후 카르마를 실행하면 '카르마'가 내부 또는 외부 명령으로 인식되지 않습니다. (0) | 2020.08.10 |
효과가 끝날 때까지 jQuery를 기다리는 방법은 무엇입니까? (0) | 2020.08.10 |