国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Android 實現仿網易新聞等主流新聞客戶端頂部標簽導航效果(GONE和INVISIBLE的區別)

mudiyouyou / 3129人閱讀

摘要:網易新聞客戶端博主要實現的效果代碼看了文件相信所有人都明朗了吧,其實每個選項卡都是的組合標題欄操作設置監聽事件這里可以進行點擊相應選項卡后進行的觸發事件,一般為顯示新聞頁面每次點擊新的選項卡都調用此方法將所有選項卡都置換為未點擊狀態,

網易新聞客戶端:

博主要實現的效果:

代碼:
view_header.xml:






    

activity_news.xml:








    

        

        
    

    

        

        
    

    

        

        
    

    

        

        
    

    

        

        
    

    

        

        
    


看了xml文件相信所有人都明朗了吧,其實每個選項卡都是TextView+ImageView的組合

News.java:

public class News extends Activity  {
private LinearLayout ll_top_left;
private TextView tv_title;
private TextView btn_headline, btn_internation, btn_inland, btn_video, btn_appraisal,
  btn_complaint;
private ImageView view_headline, view_internation, view_inland, view_video, v   iew_appraisal,
  view_complaint;
private int type = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news);
initHeader();
initTab();
}

private void initHeader() {    //標題欄操作
ll_top_left = (LinearLayout) findViewById(R.id.ll_header_left);
tv_title = (TextView) findViewById(R.id.tv_header_title);
tv_title.setText(getString(R.string.head_title_news));
ll_top_left.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    finish();
  }
});

}

private void initTab() {
btn_headline = (TextView) findViewById(R.id.tv_headline);
btn_internation = (TextView) findViewById(R.id.tv_international);
btn_inland = (TextView) findViewById(R.id.tv_inland);
btn_video = (TextView) findViewById(R.id.tv_video);
btn_appraisal = (TextView) findViewById(R.id.tv_appraisal);
btn_complaint = (TextView) findViewById(R.id.tv_complaint);

view_headline = (ImageView) findViewById(R.id.view_news_headline);
view_internation = (ImageView) findViewById(R.id.view_news_internation);
view_inland = (ImageView) findViewById(R.id.view_news_inland);
view_video = (ImageView) findViewById(R.id.view_news_video);
view_appraisal = (ImageView) findViewById(R.id.view_news_appraisal);
view_complaint = (ImageView) findViewById(R.id.view_news_complaint);
//設置監聽事件
btn_headline.setOnClickListener(new MyTabClickListener());
btn_internation.setOnClickListener(new MyTabClickListener());
btn_inland.setOnClickListener(new MyTabClickListener());
btn_video.setOnClickListener(new MyTabClickListener());
btn_appraisal.setOnClickListener(new MyTabClickListener());
btn_complaint.setOnClickListener(new MyTabClickListener());
onType(type);

}

private class MyTabClickListener implements OnClickListener {

@Override
public void onClick(View v) {
  onFocused(v.getId());
  switch (v.getId()) {
    case R.id.tv_headline:
      type = 1;
      break;
    case R.id.tv_international:
      type = 2;
      break;
    case R.id.tv_inland:
      type = 3;
      break;
    case R.id.tv_video:
      type = 4;
      break;
    case R.id.tv_appraisal:
      type = 5;
      break;
    case R.id.tv_complaint:
      type = 6;
      break;
    default:
      break;
  }
  //這里可以進行點擊相應選項卡后進行的觸發事件,一般為顯示新聞頁面
}

}

private void initTabState(){   每次點擊新的選項卡都調用此方法將所有選項卡都置換為未點擊狀態,這么做是有點麻煩,但是我還沒想到更加優雅的方法囧...
view_headline.setVisibility(View.INVISIBLE);
view_internation.setVisibility(View.INVISIBLE);
view_inland.setVisibility(View.INVISIBLE);
view_video.setVisibility(View.INVISIBLE);
view_appraisal.setVisibility(View.INVISIBLE);
view_complaint.setVisibility(View.INVISIBLE);

btn_headline.setTextColor(getResources().getColor(R.color.color_news_title_unchecked));
btn_internation.setTextColor(getResources().getColor(R.color.color_news_title_unchecked));
btn_inland.setTextColor(getResources().getColor(R.color.color_news_title_unchecked));
btn_video.setTextColor(getResources().getColor(R.color.color_news_title_unchecked));
btn_appraisal.setTextColor(getResources().getColor(R.color.color_news_title_unchecked));
btn_complaint.setTextColor(getResources().getColor(R.color.color_news_title_unchecked));

}

private void onFocused(int fid) {   點擊選項卡時調用的方法
initTabState();
switch (fid) {
  case R.id.tv_headline:
    view_headline.setVisibility(View.VISIBLE);
    btn_headline.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case R.id.tv_international:
    view_internation.setVisibility(View.VISIBLE);
    btn_internation.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case R.id.tv_inland:
    view_inland.setVisibility(View.VISIBLE);

    btn_inland.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case R.id.tv_video:
    view_video.setVisibility(View.VISIBLE);
    btn_video.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case R.id.tv_appraisal:
    view_appraisal.setVisibility(View.VISIBLE);
    btn_appraisal.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case R.id.tv_complaint:
    view_complaint.setVisibility(View.VISIBLE);
    btn_complaint.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
}

}

private void onType(int type) {   觸發監聽事件后調用
initTabState();
switch (type) {
  case 1:
    view_headline.setVisibility(View.VISIBLE);
    btn_headline.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case 2:
    view_internation.setVisibility(View.VISIBLE);
    btn_internation.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case 3:
    view_inland.setVisibility(View.VISIBLE);
    btn_inland.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case 4:
    view_video.setVisibility(View.VISIBLE);
    btn_video.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case 5:
    view_appraisal.setVisibility(View.VISIBLE);
    btn_appraisal.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
  case 6:
    view_complaint.setVisibility(View.VISIBLE);
    btn_complaint.setTextColor(getResources().getColor(R.color.color_news_title_checked));
    break;
}

}

}

關于GONE和INVISIBLE的區別有一篇中文博客講的比較好:http://blog.csdn.net/chindroid/article/details/8000713
當控件visibility屬性為INVISIBLE時,界面保留了view控件所占有的空間;而控件屬性為GONE時,界面則不保留view控件所占有的空間。

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/64130.html

相關文章

發表評論

0條評論

mudiyouyou

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<