效果图如下所示:
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实现腾讯新闻的新闻类别导航效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!