WebView里面静态内部类ExtendedZoomControls解析

WebView里面有一个静态内部类ExtendedZoomControls,其继承FrameLayout。它是对ZoomControls的扩展,它加载了一个布局文件com.android.internal.R.layout.zoom_magnify,布局文件源码如下:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >

    <ZoomControls
        android:id="@+id/zoomControls"
        style="@style/ZoomControls"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal" />

    <ImageView
        android:id="@+id/zoomMagnify"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:focusable="true"
        android:paddingEnd="2dip"
        android:src="@drawable/btn_zoom_page" />

</merge>

此布局文件引用了一个style:ZoomControls:

    <style name="ZoomControls">
        <item name="android:gravity">bottom</item>
        <item name="android:paddingStart">15dip</item>
        <item name="android:paddingEnd">15dip</item>
    </style>


所以此ExtendedZoomControls只是在ZoomControls基础上做了扩展。此控件对外提供了显示和隐藏以及设置监听的方法,源码如下:

    private static class ExtendedZoomControls extends FrameLayout {
        public ExtendedZoomControls(Context context, AttributeSet attrs) {
            super(context, attrs);
            LayoutInflater inflater = (LayoutInflater)
                    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            inflater.inflate(com.android.internal.R.layout.zoom_magnify, this, true);
            mPlusMinusZoomControls = (ZoomControls) findViewById(
                    com.android.internal.R.id.zoomControls);
            findViewById(com.android.internal.R.id.zoomMagnify).setVisibility(
                    View.GONE);
        }

        public void show(boolean showZoom, boolean canZoomOut) {
            mPlusMinusZoomControls.setVisibility(
                    showZoom ? View.VISIBLE : View.GONE);
            fade(View.VISIBLE, 0.0f, 1.0f);
        }

        public void hide() {
            fade(View.GONE, 1.0f, 0.0f);
        }

        private void fade(int visibility, float startAlpha, float endAlpha) {
            AlphaAnimation anim = new AlphaAnimation(startAlpha, endAlpha);
            anim.setDuration(500);
            startAnimation(anim);
            setVisibility(visibility);
        }

        public boolean hasFocus() {
            return mPlusMinusZoomControls.hasFocus();
        }

        public void setOnZoomInClickListener(OnClickListener listener) {
            mPlusMinusZoomControls.setOnZoomInClickListener(listener);
        }

        public void setOnZoomOutClickListener(OnClickListener listener) {
            mPlusMinusZoomControls.setOnZoomOutClickListener(listener);
        }

        ZoomControls    mPlusMinusZoomControls;
    }


提供的方法很容易看懂,就不多做解释。

你可能感兴趣的:(android,webView,Zoomcontrols,zoom_magnify)