您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
效果图如下所示:
1、在Adapter中加入如下代码
<pre ><span >private int </span><span >clickTemp </span>= -<span >1</span><span >;</span><span >//</span><span ><em>TODO </em></span><span ><em>被选择的</em></span><span ><em>item</em></span><span ><em>下标</em></span></pre><p></p> <pre ><span ><em>/** </em></span><span ><em> * </em></span><span ><em>TODO </em></span><span ><em>传入下标,设置被选择的</em></span><span ><em>item </em></span><span ><em> </em></span><span ><em>* </em></span><span ><em> * </em></span><span ><strong><em>@param </em></strong></span><span ><em>position </em></span><span ><em> </em></span><span ><em>*/ </em></span><span >public void </span><span >setSelection</span>(<span >int </span>position) { <span >clickTemp </span>= position<span >; </span>}</pre> <br> <pre></pre>
2、在Adapter的getView方法中加入如下代码
<p></p> <p></p><pre name="code" class="java"><pre ><span >//</span><span ><em>TODO </em></span><span ><em>点击改变</em></span><span ><em>item</em></span><span ><em>底部控件状态 </em></span><span >if </span>(<span >clickTemp </span>== position) {<span >//</span><span ><em>TODO </em></span><span ><em>选中的</em></span><span ><em>item</em></span><span ><em>显示底部控件 </em></span><span ><em> </em></span>typeHolder.<span >item_gv_viewBottom</span>.setVisibility(View.<span ><em>VISIBLE</em></span>)<span >; </span>} <span >else </span>{<span >//</span><span ><em>TODO </em></span><span ><em>未选中的</em></span><span ><em>item</em></span><span ><em>隐藏底部控件 </em></span><span ><em> </em></span>typeHolder.<span >item_gv_viewBottom</span>.setVisibility(View.<span ><em>INVISIBLE</em></span>)<span >; </span>}</pre><p></p> <pre></pre>
3、修改OnItemClickListener代码<br>
<pre name="code" class="java"><pre ><span ><em>/** </em></span><span ><em> * item</em></span><span ><em>点击事件 </em></span><span ><em> </em></span><span ><em>*/ </em></span>AdapterView.OnItemClickListener <span >mItemClickListener </span>= <span >new </span>AdapterView.OnItemClickListener() { <span >@Override </span><span > </span><span >public void </span><span >onItemClick</span>(AdapterView<?> parent<span >, </span>View view<span >, int </span>position<span >, long </span>id) { <span >myGridViewAdapter</span>.setSelection(position)<span >;</span><span >//</span><span ><em>TODO </em></span><span ><em>传入当前点击</em></span><span ><em>item</em></span><span ><em>的下标 </em></span><span ><em> </em></span><span >myGridViewAdapter</span>.notifyDataSetChanged()<span >;</span><span >//</span><span ><em>TODO </em></span><span ><em>刷新</em></span><span ><em>Adapter </em></span><span ><em> </em></span>} }<span >;</span></pre> <pre></pre> <br> <br> <p></p> <p><br> <br> </p> </pre></pre>
以上所述是小编给大家介绍的Android实现腾讯新闻的新闻类别导航效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对亿速云网站的支持!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。