ScrollView滚动视图和WebView

WebView直接写代码

 webView = (WebView) findViewById(R.id.webView);
        //配置webview
        webView.getSettings().setLoadsImagesAutomatically(true);//自动加载图片
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);//滚动条透明的不占用空间
        webView.getSettings().setUseWideViewPort(true);/**手机浏览器是把页面放在一个虚拟的“窗口”
         (viewport)中,通常这个虚拟的“窗口”(viewport)比屏幕宽,这样就不用把每个网页挤到很小的窗口中(这样
         会破坏没有针对手机浏览器优化的网页的布局),用户可以通过平移和缩放来看网页的不同部分。移动版的 Safari
         浏览器最新引进了 viewport 这个 meta tag,让网页开发者来控制 viewport 的大小和缩放,其他手机浏览器也
         基本支持。*/
        webView.getSettings().setLoadWithOverviewMode(true);/**用概览模式加载网页当网页大小超过webView大小时候*/
        //配置一个web客户端
        webView.setWebViewClient(new WebViewClient());
        //加载链接
        webView.loadUrl("http//www.baidu.com");

ScrollView

当展示的内容超出设备高度的时候或者类似情况下,我们就需要ScrollView了,注意滚动视图只能包含一个子元素所以如果需要多个滑动元素可以用一个布局包裹
此外如果想在其中加入一个类似于服务条款只有在阅读完成后才能点击按钮的功能:
1.当内容较少时,按钮应该始终置于屏幕底端
2.当内容超出屏幕时,按钮不应该出现,随着滑动到最后才出现。

  <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
        //1.在节点上加入这一属性将会在适当时候延长内容
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1" //将内容的高度设置为权重为1,填补空白空间
                android:id="@+id/tv_long"
                android:text="@string/long_string"
                android:textSize="50sp"/>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="View"
                android:id="@+id/btn_act"/>
        </LinearLayout>
    </ScrollView>

TextView

textView也可以设置滚动效果设置android:scrollbars="vertical"
这里写代码片
两者的区别在于textview滑动时候会触发内部的点击事件,而scrollview将两者区分开了

 <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:text="@string/long_string"
        android:scrollbars="vertical"
        android:textSize="30sp"/>

  textView = (TextView) findViewById(R.id.text);
        textView.setMovementMethod(new ScrollingMovementMethod());

HorizontalScrollView

水平滑动类似上面的

内部滑动

尝试在一个滑动列表加入另一个滑动
使用NestedScrollView

<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

        <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:padding="@dimen/default_padding"
                android:layout_height="@dimen/nested_scroll_view_height">

            <TextView
                    android:text="@string/hello_world"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"/>

        </android.support.v4.widget.NestedScrollView>

        <include layout="@layout/cards_layout"/>

    </LinearLayout>
</ScrollView>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值