常用属性:详见注释
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_v和bar_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;
}
});