Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android橫向滑動導航菜單

Android橫向滑動導航菜單

編輯:關於Android編程

1.效果圖

這裡寫圖片描述
 <喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxoMyBpZD0="2項目地址">2.項目地址

https://github.com/lynnchurch/HorizontalScrollMenu.git
 

3.使用示例代碼

package com.example.horizontalscrollmenusample;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.lynnchurch.horizontalscrollmenu.BaseAdapter;
import com.lynnchurch.horizontalscrollmenu.HorizontalScrollMenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity
{
    private HorizontalScrollMenu hsm_container;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    public void initView()
    {
        hsm_container = (HorizontalScrollMenu) findViewById(R.id.hsm_container);
        hsm_container.setAdapter(new MenuAdapter());
    }

    class MenuAdapter implements BaseAdapter
    {
        String[] names = new String[]
        { "菜單一", "菜單二", "菜單三", "菜單四", "菜單五", "菜單六", "菜單七" };

        @Override
        public List getMenuItems()
        {
            // TODO Auto-generated method stub
            return Arrays.asList(names);
        }

        @Override
        public List getContentViews()
        {
            // TODO Auto-generated method stub
            List views = new ArrayList();
            for (String str : names)
            {
                View v = LayoutInflater.from(MainActivity.this).inflate(
                        R.layout.content_view, null);
                TextView tv = (TextView) v.findViewById(R.id.tv_content);
                tv.setText(str);
                views.add(v);
            }
            return views;
        }

    }
}
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved