20120731222410402012073122251425  

package com.navigation.acitvity;

import com.navigation.constant.ConstantCategoryMenu;
import com.navigation.control.PulldownMenuView;
import com.navigation.control.PulldownMenuView.OnMenuItemClickListener;
import com.navigation.utility.MenuUtility;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * Android實現下拉導航選擇菜單效果
 * @Description: Android實現下拉導航選擇菜單效果

 * @File: MainActivity.java

 * @Package com.navigation.acitvity

 * @Author Hanyonglu

 * @Date 2012-7-28 下午06:08:27

 * @Version V1.0
 */
public class MainActivity extends Activity {
    // PulldownMenuView基本操作類
    private MenuUtility menuUtility = null;
    // 今日頭條LinearLayout
    private LinearLayout linearLayoutTopic = null;
    private RelativeLayout layoutHeader = null;
    // PulldownMenuView對象
    private PulldownMenuView pullDownMenu = null;
    
    private TextView tvTopic = null;
    private ImageView ivTopic = null; 
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initViews();
    }
    
    /**
     * 初始化
     */
    protected void initViews(){    
        menuUtility = new MenuUtility(
                MainActivity.this, 
                ConstantCategoryMenu.newsImageRes,
                ConstantCategoryMenu.newsMenuTexts);
        
        ivTopic = (ImageView) findViewById(R.id.imageViewTopic);
        tvTopic = (TextView) findViewById(R.id.textViewTopic);
        
        linearLayoutTopic = (LinearLayout)findViewById(R.id.linearLayoutTopic);
        linearLayoutTopic.setOnClickListener(TopicOnClickListener);
        layoutHeader = (RelativeLayout) findViewById(R.id.layout_top_header);
    }
    
    /**
     * 顯示PulldownMenuView
     */
    protected void showPulldownMenu(){
        pullDownMenu = menuUtility.getPulldownMenuView();
        pullDownMenu.setAnchorView(layoutHeader);
        ivTopic.setImageResource(R.drawable.ic_menu_trangle_up);
    }
    
    /**
     * 隱藏PulldownMenuView
     */
    protected void hidePulldownMenu(){
        pullDownMenu.releasePopupMenuView();
        ivTopic.setImageResource(R.drawable.ic_menu_trangle_down);
    }
    
    // 頂部今日頭條事件監聽器
    private OnClickListener TopicOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            // 開始顯示下拉菜單
            showPulldownMenu();
            
            // TODO Auto-generated method stub
            pullDownMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                
                @Override
                public void onMenuItemClick(AdapterView<?> parent, View view, int position) {
                    // TODO Auto-generated method stub
                    
                }
                
                @Override
                public void hideMenu() {
                    // TODO Auto-generated method stub
                    hidePulldownMenu();
                }
            });
            
            pullDownMenu.show();
        }
    };
}

From:CNBLOGS
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()