ScrollView和HorizontalScrollView常用属性,及禁止滑动

常用属性:详见注释
activity_main_28

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fadingEdge="none"
        android:overScrollMode="never"
        android:scrollbarThumbVertical="@drawable/bar_style_v"
        >

        <!--ScrollView滚动条不显示 android:scrollbars="none"-->
        <!--ScrollView滚动条恒显示:android:fadeScrollbars="false"-->
        <!--设置垂直滚动条的drawable(如颜色):android:scrollbarThumbVertical,如果ScrollView中使用android:scrollbarThumbHorizontal,没有效果。反之亦然-->
        <!--设置滚动条的大小:android:scrollbarSize="20dp"  ScrollView中,代表宽度-->

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

            <TextView
                style="@style/TV"
                android:text="111"
                />

            <TextView
                style="@style/TV"
                android:text="222"
                />

            <TextView
                style="@style/TV"
                android:text="333"
                />

            <TextView
                style="@style/TV"
                android:text="444"
                />

            <TextView
                style="@style/TV"
                android:text="555"
                />

            <TextView
                style="@style/TV"
                android:text="666"
                />

            <TextView
                style="@style/TV"
                android:text="777"
                />

            <TextView
                style="@style/TV"
                android:text="888"
                />

            <TextView
                style="@style/TV"
                android:text="999"
                />

            <TextView
                style="@style/TV"
                android:text="11111"
                />

            <TextView
                style="@style/TV"
                android:text="22222"
                />

            <TextView
                style="@style/TV"
                android:text="33333"
                />

            <TextView
                style="@style/TV"
                android:text="44444"
                />

            <TextView
                style="@style/TV"
                android:text="55555"
                />

            <TextView
                style="@style/TV"
                android:text="66666"
                />

            <TextView
                style="@style/TV"
                android:text="77777"
                />

            <TextView
                style="@style/TV"
                android:text="88888"
                />

            <TextView
                style="@style/TV"
                android:text="99999"
                />
        </LinearLayout>

    </ScrollView>

    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:background="#0000ff"/>

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none"
        android:overScrollMode="never"
        android:scrollbarThumbHorizontal="@drawable/bar_style_h"
        >

        <!--滚动条不显示 android:scrollbars="none"-->
        <!--滚动条恒显示:android:fadeScrollbars="false"-->
        <!--设置水平滚动条的drawable(如颜色):android:scrollbarThumbHorizontal-->
        <!--设置滚动条的大小:android:scrollbarSize="20dp"  HorizontalScrollView中,代表高度-->

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

            <TextView
                style="@style/TV"
                android:text="111"
                />

            <TextView
                style="@style/TV"
                android:text="222"
                />

            <TextView
                style="@style/TV"
                android:text="333"
                />

            <TextView
                style="@style/TV"
                android:text="444"
                />

            <TextView
                style="@style/TV"
                android:text="555"
                />

            <TextView
                style="@style/TV"
                android:text="666"
                />

            <TextView
                style="@style/TV"
                android:text="777"
                />

            <TextView
                style="@style/TV"
                android:text="888"
                />

            <TextView
                style="@style/TV"
                android:text="999"
                />

            <TextView
                style="@style/TV"
                android:text="11111"
                />

            <TextView
                style="@style/TV"
                android:text="22222"
                />

            <TextView
                style="@style/TV"
                android:text="33333"
                />

            <TextView
                style="@style/TV"
                android:text="44444"
                />

            <TextView
                style="@style/TV"
                android:text="55555"
                />

            <TextView
                style="@style/TV"
                android:text="66666"
                />

            <TextView
                style="@style/TV"
                android:text="77777"
                />

            <TextView
                style="@style/TV"
                android:text="88888"
                />

            <TextView
                style="@style/TV"
                android:text="99999"
                />
        </LinearLayout>

    </HorizontalScrollView>


</LinearLayout>

bar_style_vbar_style_h内容一样:

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

    <solid android:color="#ff0000"/>

</shape>

只是单纯展示,主activity不必做任何操作

/**
 * ScrollView
 * HorizontalScrollView
 */
public class MainActivity_28_ScrollView_HorizontalScrollView extends BaseActivity {

    @Override
    void initview() {
        setContentView(R.layout.activity_main_28);

    }

}

禁止滑动:

     scroll_view = (ScrollView) findViewById(R.id.scroll_view);
        scroll_view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                Log.e("chen", "ScrollView-onTouch");
                //不能滑动
                return true;
                //可以滑动
                //return false;
            }
        });
    horizontal_scroll_view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {

                Log.e("chen", "HorizontalScrollView-onTouch");

                //不能滑动
                return true;
                //可以滑动
                //return false;
            }
        });
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值