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

Posted 下一个秋天

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现安卓新闻客户端标题栏的左右切换的问题相关的知识,希望对你有一定的参考价值。

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的滑动距离



以上是关于实现安卓新闻客户端标题栏的左右切换的问题的主要内容,如果未能解决你的问题,请参考以下文章

安卓中实现界面数据懒加载

Android ViewPager+HorizontalScrollView实现标题栏滑动(腾讯新闻)

android 底部导航栏

安卓手机下拉状态栏的代码实现

腾讯新闻多图jQuery相册展示效果代码

android下滑动返回上一个页面如何实现