首页 > 其他分享 >Android 使用Gallery实现Tab

Android 使用Gallery实现Tab

时间:2022-10-06 11:33:52浏览次数:48  
标签:xml Java text Gallery public Tab Android android


main.xml布局文件: 

Java代码  
​​

​​


1. <?xml version="1.0" encoding="utf-8"?>
2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. "vertical" android:layout_width="fill_parent"
4. "fill_parent">
5. "@+id/gallery" android:layout_width="fill_parent"
6. "wrap_content" android:layout_marginTop="30dp"
7. "1" android:spacing="1dip"
8. </LinearLayout>



values/attrs.xml:


Java代码
​​

​​


1. <?xml version="1.0" encoding="utf-8"?>
2. <resources>
3. "Gallery">
4. "android:galleryItemBackground"
5. </declare-styleable>
6. </resources>



values/strings.xml:


Java代码
​​

​​


1. <?xml version="1.0" encoding="utf-8"?>
2. <resources>
3. "hello">Hello World, Date!</string>
4. "app_name">丸子-Widget</string>
5. </resources>



drawable/tab_button_select.xml:


Java代码
​​

​​


1. <?xml version="1.0" encoding="utf-8"?>
2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
3. "#FF1B1B1B" android:endColor="#FF969696"
4. "90.0">
5. </gradient>
6. </shape>



drawable/tab_button_unselect.xml:


Java代码
​​

​​


1. <?xml version="1.0" encoding="utf-8"?>
2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
3. "#FF000000" android:endColor="#FF474747"
4. "90.0">
5. </gradient>
6. </shape>



IaiaiActivity.java类:


Java代码
​​

​​


1. package
2.
3. import
4. import
5. import
6.
7. import
8. import
9. import
10. import
11. import
12. import
13. import
14. import
15. import
16. import
17. import
18. import
19. import
20.
21. /**
22. *
23. * <p>
24. * Title: IaiaiActivity.java
25. * </p>
26. * <p>
27. * E-Mail: [email protected]
28. * </p>
29. * <p>
30. * QQ: 176291935
31. * </p>
32. * <p>
33. * Http: iaiai.iteye.com
34. * </p>
35. * <p>
36. * Create time: 2011-6-26
37. * </p>
38. *
39. * @author 丸子
40. * @version 0.0.1
41. */
42. public class IaiaiActivity extends
43.
44. private
45. private
46.
47. private static final String[] PROGRAM_NAMES = { "中央一台", "中央二台", "中央三台",
48. "中央四台", "中央五台", "中央六台", "中央七台", "中央八台", };
49.
50. @Override
51. public void
52. super.onCreate(savedInstanceState);
53. setContentView(R.layout.main);
54.
55. gallery = (Gallery) findViewById(R.id.gallery);
56. new TabAdapter(this, Arrays.asList(PROGRAM_NAMES));
57. gallery.setAdapter(textAdapter);
58. new
59.
60. @Override
61. public void
62. int position, long
63. TabAdapter adapter = (TabAdapter) parent.getAdapter();
64. adapter.setSelectedPos(position);
65. }
66.
67. });
68. }
69.
70. public class TabAdapter extends
71. private
72. private
73. private int
74.
75. public
76. mContext = context;
77. TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
78. a.recycle();
79. if (list == null)
80. list = Collections.emptyList();
81. mList = list;
82. }
83.
84. public void setSelectedPos(int
85. if
86. mSelectedPos = pos;
87. notifyDataSetChanged();
88. }
89. }
90.
91. public int
92. return
93. }
94.
95. public int
96. return
97. }
98.
99. public Object getItem(int
100. return
101. }
102.
103. public long getItemId(int
104. return
105. }
106.
107. public View getView(int
108. null;
109. if (convertView == null) {
110. new
111. else
112. text = (TextView) convertView;
113. }
114.
115. text.setTextColor(Color.WHITE);
116. text.setText(mList.get(position));
117.
118. new Gallery.LayoutParams(102, 40));
119. text.setGravity(Gravity.CENTER);
120.
121. if
122. text.setBackgroundResource(R.drawable.tab_button_select);
123. else
124. text.setBackgroundResource(R.drawable.tab_button_unselect);
125.
126. return
127. }
128. }
129.
130. }



运行结果: 


Android 使用Gallery实现Tab_java


标签:xml,Java,text,Gallery,public,Tab,Android,android
From: https://blog.51cto.com/jdsjlzx/5733504

相关文章

  • Android Asynchronous HTTPClient的实现和优化
    大家知道Android对UI线程的反应时间要求很高,超过5秒钟直接ANR掉,根本不给你机会多等。而Android应用与后端系统的交互是最基本的需求之一,如何实现高效的AsynchronousHTTPCli......
  • Android GridView控件自定义
    虽然​​Android​​​已自带了GridView,但是,却不够灵活,同时也不能自由添加控件,因此,本人通过需要进一步封装,来实现​​Android自定义GridView控件​​,达到自己需要的效果。......
  • Android实现渐显按钮的左右滑动效果
    本示例演示在Android中实现带渐显按钮的左右滑动效果。关于滑动效果,在我的上一篇博文中提到过,有兴趣的朋友可以访问如果大家想实现带指引效果的左右滑动,请访问博先看下......
  • Android闪屏示例程序
     用过手机QQ的基本上都知道,刚启动程序时候会在一个界面停留一会,按任意键的就直接跳过,这就是所谓的闪屏。那么,在Android中怎样实现这样的效果呢? 1、新建一个Android项目,命......
  • Android实现图片倒影效果
    ​​android倒影实现抖动的镜面效果​​​​http://clareshao.iteye.com/blog/1419695​​android中的gallery的一个样式,具有倒影效果。左右滑动也不错。​​http://down......
  • Android开发--构建项目安装包APK(debug版)
    1.build→BuildAPK(s),点击即可构建2.点击日志可以查看构建情况3.点击locate即可进入debug文件夹4.也可以在构建完成后直接按照路径找到debug文件夹其中apk文件即所需安装......
  • iptables语法
    ####filter是最常用的#iptables-nvL查看默认规则#serviceiptablesrestart重启iptables服务#systemctlrestartiptables重启iptables服务#serviceiptablessave......
  • iptables filter表小案例
    ####iptables小案例#vi/usr/local/sbin/iptables.sh编写脚本写入需求#加入:##!/bin/bash#ipt="/usr/sbin/iptables"#定义变量#$ipt-F#清空规则,不-t......
  • Android类加载流程
    背景由于前前前阵子写了个壳,得去了解类的加载流程,当时记了一些潦草的笔记。这几天把这些东西简单梳理了一下,本文分析的代码基于Android8.1.0源码。流程分析从loadClass......
  • 2.iptables规则管理
    1.什么是iptables规则数据包的过滤是基于规则,规则是由“匹配条件”+“动作”组成。我们对规则的操作是增删改查操作规则的语法:iptables[-t][表名]选项[链名][规则]......