태그 보관물: android-layout

android-layout

데이터가로드 된 후 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가로드 된 후 자동으로 스크롤되는 것처럼 보입니다. 이것을 어떻게 방지합니까?



답변

LinearLayout에 간단히 추가 할 수 있습니다 : android : focusableInTouchMode = “true”. 그것은 나를 위해 작동합니다.

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


답변

몇 시간 동안 몇 시간 동안 아이디어를 시도한 후 동일한 문제가 발생했습니다. 마지막으로 효과가 있었던 descendantFocusability것은 값이있는 ScrollView의 LinearLayout을 포함 하는 속성을 추가하는 것 blocksDescendants입니다. 귀하의 경우 :

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

그 이후로 문제가 다시 발생하지 않았습니다.


답변

ScrollView를 확장 한 다음 requestChildFocus를 재정의하는 새 클래스를 만들어야합니다.

public class MyScrollView extends ScrollView {

    @Override
    public void requestChildFocus(View child, View focused) {
        if (focused instanceof WebView )
           return;
        super.requestChildFocus(child, focused);
    }
}

그런 다음 XML 레이아웃에서 다음을 사용합니다.

<MyScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background" >

그것은 나를 위해 작동합니다. ScrollView는 더 이상 WebView로 자동 스크롤되지 않습니다.


답변

기본 레이아웃에이 줄을 추가하면 문제가 해결됩니다.

android:descendantFocusability="blocksDescendants"


답변

이렇게 :

<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" >


답변

아마 저와 똑같은 문제를 가진 사람들이있을 것입니다. 그래서 제가 도와 드리겠습니다.

다음과 같이 기본 ScrollView 에 android : descendantFocusability = “beforeDescendants” 를 넣으려고했습니다 .

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="beforeDescendants">
    /*my linearlayout or whatever to hold the views */

작동하지 않았기 때문에 RelativeLayout을 ScrollView의 부모로 만들고 android : descendantFocusability = “beforeDescendants” 를 부모에도 배치해야했습니다.

그래서 다음과 같이 해결했습니다.

<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 */


답변

MyScrollView에 대해 정규화 된 이름을 사용해야했습니다. 그렇지 않으면 팽창 예외가 발생했습니다.

<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" >