欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-11 19:07:04
效果图如下所示:  1、在adapter中加入如下代码
						

效果图如下所示:

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

 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实现腾讯新闻的新闻类别导航效果,希望对大家有所帮助

上一篇:

下一篇: