有办法使用seekbar来控制scrollview不能滚动的滚动位置么

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&android第一行代码流水记录(12)
用SeekBar控制CardView的边角和景深
CardView继承FrameLayout,FrameLayout用于在屏幕部分区域去显示一个控件。CardView的elevation特性需要在API21以上才能使用。
1、新建activity_card_view.xml
activity_card_view.xml,CardViewActivity的布局文件
框架布局是最简单的布局形式,所有添加到这个布局中的文件都以层叠方式显示
&FrameLayout xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.android.cardview.CardViewActivity"
tools:ignore="MergeRootFrame" /&
2、新建activity_main.xml
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"&
&LinearLayout style="@style/Widget.SampleMessageTile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"&
&TextView style="@style/Widget.SampleMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/horizontal_page_margin"
android:layout_marginRight="@dimen/horizontal_page_margin"
android:layout_marginTop="@dimen/vertical_page_margin"
android:layout_marginBottom="@dimen/vertical_page_margin"
android:text="@string/intro_message" /&
&/LinearLayout&
&/LinearLayout&
3、新建fragment_card_view.xml
fragment_card_view.xml碎片布局CardView和SeekBar
ScrollView滚动视图是指当拥有很多内容,屏幕显示不完时,需要通过滚动跳来显示的视图。ScrollView只支持垂直滚动。
xmlns:android="/apk/res/android"
xmlns:card_view="/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:id="@+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:elevation="100dp"
card_view:cardBackgroundColor="@color/cardview_initial_background"
card_view:cardCornerRadius="8dp"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
android:text="@string/cardview_contents"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:orientation="horizontal"
android:layout_width="@dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/cardview_radius_seekbar_text"
android:id="@+id/cardview_radius_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="@dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/cardview_elevation_seekbar_text"
android:id="@+id/cardview_elevation_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
4、建立CardViewActivity,使用FragmentManager与碎片CardViewFragment关联
public class CardViewActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_view);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, CardViewFragment.newInstance())
.commit();
5、建立CardViewFragment,实例化CardView和SeekBar,使用setOnSeekBarChangeListener()监听SeekBar变化,setRadius()和setElevation()分别改变CardView的边角弧度和立体深度。
package com.example.android.
import android.app.F
import android.os.B
import android.support.v7.widget.CardV
import android.util.L
import android.view.LayoutI
import android.view.V
import android.view.ViewG
import android.widget.SeekB
* Fragment that demonstrates how to use CardView.
public class CardViewFragment extends Fragment {
private static final String TAG = CardViewFragment.class.getSimpleName();
/** The CardView widget. */
CardView mCardV
* SeekBar that changes the cornerRadius attribute for the {@link #mCardView} widget.
SeekBar mRadiusSeekB
* SeekBar that changes the Elevation attribute for the {@link #mCardView} widget.
SeekBar mElevationSeekB
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
* A new instance of fragment NotificationFragment.
public static CardViewFragment newInstance() {
CardViewFragment fragment = new CardViewFragment();
fragment.setRetainInstance(true);
public CardViewFragment() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_card_view, container, false);
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mCardView = (CardView) view.findViewById(R.id.cardview);
mRadiusSeekBar = (SeekBar) view.findViewById(R.id.cardview_radius_seekbar);
mRadiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.d(TAG, String.format("SeekBar Radius progress : %d", progress));
mRadiusSeekBar.setMax(200);
mCardView.setRadius(progress);
public void onStartTrackingTouch(SeekBar seekBar) {
public void onStopTrackingTouch(SeekBar seekBar) {
mElevationSeekBar = (SeekBar) view.findViewById(R.id.cardview_elevation_seekbar);
mElevationSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.d(TAG, String.format("SeekBar Elevation progress : %d", progress));
mCardView.setElevation(progress);
public void onStartTrackingTouch(SeekBar seekBar) {
public void onStopTrackingTouch(SeekBar seekBar) {
6、AndroidManifest.xml声明权限和配置定义文件。
xmlns:android="/apk/res/android"
package="com.example.android.cardview"
android:versionCode="1"
android:versionName="1.0" &
android:minSdkVersion="7"
android:targetSdkVersion="21" /&
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" &
android:name=".CardViewActivity"
android:label="@string/app_name" &
android:name="android.intent.action.MAIN" /&
android:name="android.intent.category.LAUNCHER" /&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:18277次
排名:千里之外
原创:31篇
转载:48篇
(1)(3)(2)(10)(14)(9)(4)(42)iOS开发UI篇—UIScrollView控件介绍 - 文顶顶 - 博客园
最怕你一生碌碌无为 还安慰自己平凡可贵
iOS开发UI篇&UIScrollView控件介绍
一、知识点简单介绍
1.UIScrollView控件是什么?
(1)移动设备的屏幕?大?小是极其有限的,因此直接展?示在?用户眼前的内容也相当有限
(2)当展?示的内容较多,超出?一个屏幕时,?用户可通过滚动?手势来查看屏幕以外的内容
(3)普通的UIView不具备滚动功能,不能显?示过多的内容
(4)UIScrollView是一个能够滚动的视图控件,可以?用来展?示?大量的内容,并且可以通过滚 动查看所有的内容
&(5)& 举例:手机上的&设置&、其他?示例程序&
2.UIScrollView的简单使用
(1)将需要展?的内容添加到UIScrollView中
(2)设置UIScrollView的contentSize属性,告诉UIScrollView所有内容的尺?寸,也就是告诉 它滚动的范围(能滚多远,滚到哪?里是尽头)&
(1)常用属性:
1)@property(nonatomic)CGPointcontentO 这个属性?用来表?示UIScrollView滚动的位置
2)@property(nonatomic)CGSizecontentS这个属性?用来表?示UIScrollView内容的尺?寸,滚动范围(能滚多远)
3)@property(nonatomic)UIEdgeInsetscontentI 这个属性能够在UIScrollView的4周增加额外的滚动区域&
(2)其他属性:
1)@property(nonatomic) BOOL
&设置UIScrollView是否需要弹簧效果&
2)@property(nonatomic,getter=isScrollEnabled)BOOLscrollE 设置UIScrollView是否能滚动&
3)@property(nonatomic) BOOL showsHorizontalScrollI 是否显?示?水平滚动条&
4)@property(nonatomic) BOOL showsVerticalScrollI 是否显?示垂直滚动条&
& 如果UIScrollView?无法滚动,可能是以下原因:
(1)没有设置contentSize
(2) scrollEnabled = NO
(3)&没有接收到触摸事件:userInteractionEnabled = NO
(4)没有取消autolayout功能(要想scrollView滚动,必须取消autolayout)&
二、关于UIScrollView常见属性的一些说明
1.属性使用的代码示例
1 #import "MJViewController.h"
3 @interface MJViewController ()
//在私有扩展中创建一个属性
UIScrollView *_scrollV
10 @implementation MJViewController
12 - (void)viewDidLoad
[super viewDidLoad];
// 1.创建UIScrollView
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = CGRectMake(0, 0, 250, 250); // frame中的size指UIScrollView的可视范围
scrollView.backgroundColor = [UIColor grayColor];
[self.view addSubview:scrollView];
// 2.创建UIImageView(图片)
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"big.jpg"];
CGFloat imgW = imageView.image.size. // 图片的宽度
CGFloat imgH = imageView.image.size. // 图片的高度
imageView.frame = CGRectMake(0, 0, imgW, imgH);
[scrollView addSubview:imageView];
// 3.设置scrollView的属性
// 设置UIScrollView的滚动范围(内容大小)
scrollView.contentSize = imageView.image.
// 隐藏水平滚动条
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
// 用来记录scrollview滚动的位置
scrollView.contentOffset = ;
// 去掉弹簧效果
scrollView.bounces = NO;
// 增加额外的滚动区域(逆时针,上、左、下、右)
scrollView.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);
_scrollView = scrollV
52 - (IBAction)down:(UIButton *)sender {
[UIView animateWithDuration:1.0 animations:^{
//三个步骤
CGPoint offset = _scrollView.contentO
offset.y += 150;
_scrollView.contentOffset =
//_scrollView.contentOffset = CGPointMake(0, 0);
2.几个属性坐标示意图
3.重要说明
(1)UIScrollView的frame与contentsize属性的区分:UIScrollView的frame指的是这个scrollview的可视范围(可看见的区域),contentsize是其滚动范围。
(2)contentinset(不带*号的一般不是结构体就是枚举),为UIScrollView增加额外的滚动区域。(上,左,下,右)逆时针。contentinset可以使用代码或者是视图控制器进行设置,但两者有区别(注意区分)。
(3)contentsize属性只能使用代码设置。
(4)contentoffset是个CGpoint类型的结构体,用来记录ScrollView的滚动位置,即记录着&框&跑到了哪里。知道了这个属性,就知道了其位置,可以通过设置这个属性来控制这个&框&的移动。
(5)不允许直接修改某个对象内部结构体属性的成员,三个步骤(先拿到值,修改之,再把修改后的值赋回去)。
(6)增加了额外区域后,contentoffset的原点在哪里?
三、有助于理解的几个截图
随笔 - 178
评论 - 1366Android(74)
&&&&&& 在默认情况下,HorizontalScrollView控件里面的内容在滚动的情况下,会出现滚动条,为了去掉滚动条,只需要在&HorizontalScrollView/&里面加一句&&& android:scrollbars=&none&。
&&&&&&& 如果想实现在代码里面,点击左(右)按钮【btnLeft(btnRight)】,滚动条里面的内容会向左向右滚动【horizontalScrollViewMM】。代码如下:
&&&&&&&&&滚动条向左滚动:
&&&&&&&& btnLeft.setOnClickListener( new View.onClickListener(){
&&&&&&&&&&&&&&&&&& horizontalScrollViewMM.arrowScroll(View.FOCUS_LEFT);
滚动条向右滚动:
&&&&& btnRight.setOnClickListener( new View.onClickListener(){
&&&&& horizontalScrollViewMM.arrowScroll(View.FOCUS_RIGHT)
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:71295次
积分:1726
积分:1726
排名:第16275名
原创:77篇
转载:176篇
(2)(1)(1)(3)(1)(5)(1)(3)(3)(6)(5)(10)(3)(3)(7)(4)(9)(8)(7)(8)(14)(8)(8)(19)(8)(7)(7)(6)(16)(6)(8)(16)(14)(12)(7)(4)ViewPager和ScrollView头部滚动事件冲突解决 - 突袭新闻
当前位置&:&&&&ViewPager和ScrollView头部滚动事件冲突解决
热门标签:&
ViewPager和ScrollView头部滚动事件冲突解决
编辑:张德勇评论:
QuickNews新闻客户端源码?介绍:QuickNews新闻客户端源码,本项目主要采用slidingmenu实现侧滑NineOldAndroids,androidannotations,discrollview,ListViewAnimations,PhotoView等等来实现ViewPager和ScrollView头部效果,PhotoView来实现预览大图,本项目适合做开源框架使用,开发的小伙...
QuickNews新闻客户端源码?
QuickNews新闻客户端源码,本项目主要采用slidingmenu实现侧滑NineOldAndroids , androidannotations ,discrollview ,ListViewAnimations ,PhotoView 等等来实现 ViewPager和ScrollView头部效果,PhotoView 来实现预览大图,本项目适合做开源框架使用, 开发的小伙伴们你们争取把这个项目熟悉,什么框架都是小菜了
运行效果:
ArcAnimator动态输入参数旋转圆弧
TriXigT-VectorTD-master一款简单的游戏开发
MaterialRangeSlider双向拖动seekbar
QuickNews新闻客户端源码
PinView 自定义view
ToggleExpandLayout 页面展示特效
ArrowDownloadButton下载按钮从点击到下载完成特效
AutoLabelUI 点击列表每一个item动态添加标签
AppManager-for-Android App应用管理
Collage 相册随机展示相片特效
项目下载:/code/00/100499.html
星火燎原!这些武汉初创项目已获VC青睐
第三方支付寒冬来临:基本功能被砍 银行梦破碎
新一代品牌崛起!借鉴了苹果的Under Armour就这样打败了阿迪达斯
本网最新文章}

我要回帖

更多关于 scrollview滚动到顶部 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信