Android 实现横向标题栏滚动效果(HorizontalScrollView + GridView + Viewpager + 自定义适配器)

本文介绍如何在Android项目中实现横向标题栏滚动效果,结合HorizontalScrollView、GridView、ViewPager和自定义适配器,创建新闻客户端的UI界面。
摘要由CSDN通过智能技术生成

       最近在完成一个新闻客户端项目时,需要做出一个横向标题栏的UI界面,在网上查阅多时,感觉不是很懂,最后自己摸索出来了一种更容易理解,且更加容易的实现方法,废话不多说上图:

                                                                        
    首先布局文件
     
    activity_main.xml是主UI的布置,one_layout 到ten_layout是10个按下标题信息所对应的界面,activity_main代码如下:
   
<span style="font-size:18px;"><span style="font-size:18px;"><?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" >
        
      <HorizontalScrollView 
                           android:id="@+id/horizontal"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_marginTop="30dip"
                           android:layout_gravity="center_vertical"
                           >
              <LinearLayout
                                               android:layout_width="wrap_content"
                                               android:layout_height="wrap_content"
                                               android:orientation="horizontal"
                                               android:id="@+id/showtitle"
                                            android:layout_gravity="center_vertical"
                                                  >
               </LinearLayout>
       </HorizontalScrollView>
      <android.support.v4.view.ViewPager
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:id="@+id/showtitle_content"
          >
                
      </android.support.v4.view.ViewPager>
</LinearLayout></span></span>
     如上图代码所示 主界面使用2个控件 HorizontalScrollView ,与 ViewPager 组件,这两种是android SDK中自
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值