Add native footer view to webview

断了今生、忘了曾经 提交于 2019-12-05 02:02:47

Wrap a simple Webview, with a footer (LinearLayout, RelativeLayout, etc) inside an ObservableScrollView, rather than an ObservableWebView. I cannot go into details as you haven't added any layout files.

EDIT:

Activity.xml:

<LinearLayout   
   android:layout_width="match parent"  
   android:layout_height="match parent"  
   android:orientation="vertical">  
   <com.github.ksoichiro.android.observablescrollview.ObservableScrollView
           android:id="@+id/viewObj" 
           android:layout_width="match parent"  
           android:layout_height="wrap_content">
    <!-- Webview and footer programatically added here -->
    </com.github.ksoichiro.android.observablescrollview.ObservableScrollView
</LinearLayout> 

Activity.java:

FrameLayout.LayoutParams footerParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
FrameLayout.LayoutParams webviewParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

mWebView = new WebView(getContext());
mFooterContainer = new FrameLayout(getContext());

mObservableScrollView = (ObservableScrollView) findViewbyId(R.id.viewObj);
mObservableScrollView.addView(mWebView, webviewParams);
mObservableScrollView.addView(mFooterContainer, footerParams);

I achieved this using layout xml code as follows:

    <TextView
        android:id="@+id/about_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:textAppearanceMedium"
        />

    <TextView
        android:id="@+id/readme_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/changelog_text" />
    <WebView
        android:id="@+id/readme_content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbars="vertical" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal">

        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.5" />

        <cu.tellistico.ImageButtonText
            android:id="@+id/btn_gift"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"

            android:contentDescription="@string/btn_donate_info"
            custom:buttonBackground="@drawable/states_orange"
            android:src="@drawable/ic_gift"
            android:text="Donar"
            android:textColor="@color/text_orange" />

        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.5"/>
    </LinearLayout>

</LinearLayout>

Below the blue text there is a scrollable Webview, and a button footer. Is this valid for you?

If I've understood you right, you are trying to show/hide the footer when the WebView is scrolled, right? If so, I don't think you need a third party library to achieve this. You can extend the WebView and override the method onScrollChanged(). It is called when the horizontal or vertical scroll are changing. If the vertical scroll has changed and it is positive, show the footer, otherwise - hide it.

Another idea: have you tried the new design library shipped by Google? There is a convenient way to achieve such behavior for ListView or RecyclerView.

Correct me if I'm wrong, but basically you want to have your footer view at the bottom of the page and your webview take up all of the space that's left?

Why don't you just put your footer view inside a RelativeLayout with the alignParentBottom set to true, then have your WebView be above your custom view, with the height set to matchParent?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!