Android实现腾讯新闻的新闻类别导航效果

Dulcea ·
更新时间:2024-11-10
· 904 次阅读

效果图如下所示:

 1、在Adapter中加入如下代码

<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'OCR A Std';font-size:10.2pt;"><span style="color:#cc7832;">private int </span><span style="color:#9876aa;">clickTemp </span>= -<span style="color:#6897bb;">1</span><span style="color:#cc7832;">;</span><span style="color:#808080;">//</span><span style="color:#a8c023;"><em>TODO </em></span><span style="color:#a8c023;font-family:'宋体';"><em>被选择的</em></span><span style="color:#a8c023;"><em>item</em></span><span style="color:#a8c023;font-family:'宋体';"><em>下标</em></span></pre><p></p> <pre style="background-color:#2b2b2b; color:#a9b7c6; font-family:'OCR A Std'; font-size:10.2pt"><span style="color:#629755"><em>/** </em></span><span style="color:#629755"><em> * </em></span><span style="color:#a8c023"><em>TODO </em></span><span style="color:#a8c023; font-family:'宋体'"><em>传入下标,设置被选择的</em></span><span style="color:#a8c023"><em>item </em></span><span style="color:#a8c023"><em> </em></span><span style="color:#629755"><em>* </em></span><span style="color:#629755"><em> * </em></span><span style="color:#629755"><strong><em>@param </em></strong></span><span style="color:#8a653b"><em>position </em></span><span style="color:#8a653b"><em> </em></span><span style="color:#629755"><em>*/ </em></span><span style="color:#cc7832">public void </span><span style="color:#ffc66d">setSelection</span>(<span style="color:#cc7832">int </span>position) { <span style="color:#9876aa">clickTemp </span>= position<span style="color:#cc7832">; </span>}</pre> <br> <pre></pre>

2、在Adapter的getView方法中加入如下代码 

<p></p> <p></p><pre name="code" class="java"><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'OCR A Std';font-size:10.2pt;"><span style="color:#808080;">//</span><span style="color:#a8c023;"><em>TODO </em></span><span style="color:#a8c023;font-family:'宋体';"><em>点击改变</em></span><span style="color:#a8c023;"><em>item</em></span><span style="color:#a8c023;font-family:'宋体';"><em>底部控件状态 </em></span><span style="color:#cc7832;">if </span>(<span style="color:#9876aa;">clickTemp </span>== position) {<span style="color:#808080;">//</span><span style="color:#a8c023;"><em>TODO </em></span><span style="color:#a8c023;font-family:'宋体';"><em>选中的</em></span><span style="color:#a8c023;"><em>item</em></span><span style="color:#a8c023;font-family:'宋体';"><em>显示底部控件 </em></span><span style="color:#a8c023;font-family:'宋体';"><em> </em></span>typeHolder.<span style="color:#9876aa;">item_gv_viewBottom</span>.setVisibility(View.<span style="color:#9876aa;"><em>VISIBLE</em></span>)<span style="color:#cc7832;">; </span>} <span style="color:#cc7832;">else </span>{<span style="color:#808080;">//</span><span style="color:#a8c023;"><em>TODO </em></span><span style="color:#a8c023;font-family:'宋体';"><em>未选中的</em></span><span style="color:#a8c023;"><em>item</em></span><span style="color:#a8c023;font-family:'宋体';"><em>隐藏底部控件 </em></span><span style="color:#a8c023;font-family:'宋体';"><em> </em></span>typeHolder.<span style="color:#9876aa;">item_gv_viewBottom</span>.setVisibility(View.<span style="color:#9876aa;"><em>INVISIBLE</em></span>)<span style="color:#cc7832;">; </span>}</pre><p></p> <pre></pre>

3、修改OnItemClickListener代码<br> 

<pre name="code" class="java"><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'OCR A Std';font-size:10.2pt;"><span style="color:#629755;"><em>/** </em></span><span style="color:#629755;"><em> * item</em></span><span style="color:#629755;font-family:'宋体';"><em>点击事件 </em></span><span style="color:#629755;font-family:'宋体';"><em> </em></span><span style="color:#629755;"><em>*/ </em></span>AdapterView.OnItemClickListener <span style="color:#9876aa;">mItemClickListener </span>= <span style="color:#cc7832;">new </span>AdapterView.OnItemClickListener() { <span style="color:#bbb529;">@Override </span><span style="color:#bbb529;"> </span><span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">onItemClick</span>(AdapterView<?> parent<span style="color:#cc7832;">, </span>View view<span style="color:#cc7832;">, int </span>position<span style="color:#cc7832;">, long </span>id) { <span style="color:#9876aa;">myGridViewAdapter</span>.setSelection(position)<span style="color:#cc7832;">;</span><span style="color:#808080;">//</span><span style="color:#a8c023;"><em>TODO </em></span><span style="color:#a8c023;font-family:'宋体';"><em>传入当前点击</em></span><span style="color:#a8c023;"><em>item</em></span><span style="color:#a8c023;font-family:'宋体';"><em>的下标 </em></span><span style="color:#a8c023;font-family:'宋体';"><em> </em></span><span style="color:#9876aa;">myGridViewAdapter</span>.notifyDataSetChanged()<span style="color:#cc7832;">;</span><span style="color:#808080;">//</span><span style="color:#a8c023;"><em>TODO </em></span><span style="color:#a8c023;font-family:'宋体';"><em>刷新</em></span><span style="color:#a8c023;"><em>Adapter </em></span><span style="color:#a8c023;"><em> </em></span>} }<span style="color:#cc7832;">;</span></pre> <pre></pre> <br> <br> <p></p> <p><br> <br> </p> </pre></pre>

以上所述是小编给大家介绍的Android实现腾讯新闻的新闻类别导航效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!

您可能感兴趣的文章:Android仿京东分类模块左侧分类条目效果Android使用Scroll+Fragment仿京东分类效果Android 仿京东、拼多多商品分类页的示例代码Android实现网易Tab分类排序控件实现Android使用分类型RecyclerView仿各大商城首页Android编程实现仿美团或淘宝的多级分类菜单效果示例【附demo源码下载】android使用 ScrollerView 实现 可上下滚动的分类栏实例Android 仿网易新闻客户端分类排序功能Android学习教程之分类侧滑菜单(5)Android仿京东手机端类别页



类别 腾讯 Android

需要 登录 后方可回复, 如果你还没有账号请 注册新账号