android 控件之HorizontalScrollView

之前由于工作的原因,需要实现一个类似于网易新闻的标签栏样式的布局,乍眼一看,可以使用Gallery,但是由于Google已经放弃了gallery,所以查阅资料后发现可以使用HorizontalScrollView来实现。今天,就让我们一起来探究一下HorizontalScrollView吧。


话不多说,先上效果图



实现这种效果很简单:

1》利用Google提供的原生的HorizontalScrollView+LinearLayout实现横向滑动

2》点击的时候记录滑动的距离,然后使用scrollTo()方法来实现滑动效果。


在开始实现这个功能之前,我们还是先回顾下HorizontalScrollView的简单用法

1.布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  >  
        
   <HorizontalScrollView  
       android:layout_width="wrap_content"  
       android:layout_height="150dp"  
       android:layout_gravity="center_vertical"  
       android:background="#AA444444"  
       android:scrollbars="none" >  
      
       <LinearLayout  
           android:id="@+id/id_gallery"  
           android:layout_width="wrap_content"  
           android:layout_height="wrap_content"  
           android:layout_gravity="center_vertical"  
           android:orientation="horizontal" />  
            
    </HorizontalScrollView>  
</LinearLayout>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值