实现安卓新闻客户端标题栏的左右切换的问题

1.

 <RelativeLayout
        android:id="@id/classify_background"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@mipmap/classify_background"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        >
        <Button
            android:id="@id/classifyArrowRigh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="9dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/classify_arrow_righr_selected"
            />
        <Button
            android:id="@id/classifyArrowLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="10dp"
            android:layout_centerVertical="true"
            android:layout_marginBottom="9dp"
            android:background="@drawable/classify_arrow_left_selected"
            />


        <!--可以滚动的滚动条 android:layout_toLeftOf="@id/classifyArrowRigh"滚动的方向,这句很重要,
        不写都显示不出来 android:scrollbars="none":隐藏滚动条-->
        <HorizontalScrollView
            android:id="@id/horizontalScView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbars="none"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@id/classifyArrowLeft"
            android:layout_toLeftOf="@id/classifyArrowRigh"

            >
            <LinearLayout
                android:id="@id/classify_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal">

            </LinearLayout>
            <!--要在这个layout里面填充内容也可以在里面用GradView-->

        </HorizontalScrollView>

设置两个button的左右滑动关键代码是:

android:layout_toRightOf="@id/classifyArrowLeft" android:layout_toLeftOf="@id/classifyArrowRigh"
2.在java文件设置单击事件的时候,左右两个按钮都要有各自的滑动距离,而且滑动方向不一样(正负),并不是两个按钮共用一个滑动距离,这样两个按钮实现的就都是一个同向滑动功能了。
private final int flingveLocitypx=800;//右边按钮的滑动距离,android:layout_toLeftOf 
private final int flingveLocitypx1=-800;//左边按钮的滑动距离android:layout_toRightOf
,另外还要设置两个各自的单击事件,调用各自gradview的滑动距离

转载于:https://www.cnblogs.com/cmslby/p/6055308.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值