[android] 练习viewpagerindicator的使用(一)
2023-02-18 15:47:42 时间
主要是学习一下使用这个库
activity_main.xml
<?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:background="#eee" android:orientation="vertical" > <include layout="@layout/main_head"/> <com.viewpagerindicator.TabPageIndicator android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/vpi_tab" android:background="#C0D0E0"> </com.viewpagerindicator.TabPageIndicator> <android.support.v4.view.ViewPager android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:id="@+id/vp_content"/> </LinearLayout>
MainActivity.java
package com.example.csdn; import com.viewpagerindicator.TabPageIndicator; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { private TabPageIndicator tpi_tab; private ViewPager vp_content; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tpi_tab = (TabPageIndicator) findViewById(R.id.vpi_tab); vp_content = (ViewPager) findViewById(R.id.vp_content); FragmentManager fm = getSupportFragmentManager(); TabAdapter adapter = new TabAdapter(fm); // ViewPager设置适配器 vp_content.setAdapter(adapter); // 指示器绑定ViewPager tpi_tab.setViewPager(vp_content, 0); } } /** * 适配器 * * @author taoshihan * */ class TabAdapter extends FragmentPagerAdapter { public static final String[] TITLES = new String[] { "业界", "移动", "研发" }; public TabAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int arg0) { return new Fragment(); } @Override public int getCount() { return TITLES.length; } @Override public CharSequence getPageTitle(int position) { // TODO Auto-generated method stub return TITLES[position % TITLES.length]; } }
相关文章
- Android 加载图片占用内存分析
- Android 原生 SQLite 数据库的一次封装实践
- Android 多语言动态更新方案探索
- 新主题基于Bootstrap3
- 技术实操| 自有App如何引入小游戏(Android篇)
- 在Android系统上运行frp
- 查询IOS可降级版本
- 微信小程序 Spdier - OfferShow 反编译逆向(一)
- Android 组件化最佳实践 ARetrofit 原理
- java商城小程序收藏
- 巴士团小程序
- 微信小程序this作用域
- 从零开始搞监控系统(5)——小程序监控
- Pyinstaller打包配置UPX缩小程序包大小,打包时出现UPX is not available处理方法
- 如何将小程序游戏引入自有APP?(Android篇)
- 超级App成为小程序流量新的变现突破口
- 小程序小游戏怎样实现在自己的App里上架运行?
- Vue 网络请求模块封装 (axios)
- 微信小程序中的支付宝支付
- 小程序中商家入驻提醒、新订单提醒