时间:2021-05-20
效果图如下所示:
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实现腾讯新闻的新闻类别导航效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
关于实现网易新闻客户端的界面,以前写过很多博客,请参考:Android实现网易新闻客户端效果Android实现网易新闻客户端侧滑菜单(一)Android实现网易
为了实现这个演示,Insus.NET使用通用的新闻例子,它类别(目录)以及文章。在一个页面,显示所有类别,每个目录下显示最新几条新闻。效果如下:目录是用Data
本文实例讲述了Android开发实现自定义新闻加载页面功能。分享给大家供大家参考,具体如下:一、概述:1、效果演示:2、说明:在新闻页面刚加载的时候,一般会出现
vue实现菜单切换,点击菜单导航切换不同的内容以及为当前点击的选项添加样式,或者组件。method里:css:html代码:学校新闻就业新闻行业新闻js代码:d
DIV+CSS实现选项卡tab效果 CSS代码:JS代码:HTML代码:新闻1新闻2新闻3新闻4www.xinqinsheji.comwww.xinqin