码迷,mamicode.com
首页 > 其他好文 > 详细

旋转转盘选择Menu--第三方开源--CircleMenu

时间:2015-12-13 23:44:06      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 CircleMenu在github上的项目主页是:https://github.com/zhangphil/Android-CircleMenu 

CircleMenu用法简单,JAVA代码:

package com.szugyi.circlemenu;


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

import com.szugyi.circlemenu.view.CircleImageView;
import com.szugyi.circlemenu.view.CircleLayout;
import com.szugyi.circlemenu.view.CircleLayout.OnItemClickListener;
import com.szugyi.circlemenu.view.CircleLayout.OnItemSelectedListener;

public class MainActivity extends Activity implements OnItemSelectedListener, OnItemClickListener{
    
    private    TextView selectedTextView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        CircleLayout circleMenu = (CircleLayout)findViewById(R.id.main_circle_layout);
        circleMenu.setOnItemSelectedListener(this);
        circleMenu.setOnItemClickListener(this);

        //这个TextView仅仅作为演示转盘按钮以何为默认的选中项,
        //默认的最底部的那一条被选中,然后显示到该TextView中。
        selectedTextView = (TextView)findViewById(R.id.main_selected_textView);
        selectedTextView.setText(((CircleImageView)circleMenu.getSelectedItem()).getName());
    }

    //圆盘转动到底部,则认为该条目被选中
    @Override
    public void onItemSelected(View view, int position, long id, String name) {        
        selectedTextView.setText(name);
    }

    //选择了转盘中的某一条。
    @Override
    public void onItemClick(View view, int position, long id, String name) {
        Toast.makeText(getApplicationContext(), getResources().getString(R.string.start_app) + " " + name, Toast.LENGTH_SHORT).show();
    }
}

 

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:circle="http://schemas.android.com/apk/res/com.szugyi.circlemenu"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <com.szugyi.circlemenu.view.CircleLayout
        android:id="@+id/main_circle_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/main_selected_textView"
        android:layout_gravity="center_horizontal"
        circle:firstChildPosition="South"
        circle:isRotating="true"
        circle:rotateToCenter="true" >

        <!-- circle:circleBackground="@drawable/green"   -->

        <com.szugyi.circlemenu.view.CircleImageView
            android:id="@+id/main_facebook_image"
            circle:name="@string/facebook"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:src="@drawable/icon_facebook" />

        <com.szugyi.circlemenu.view.CircleImageView
            android:id="@+id/main_myspace_image"
            circle:name="@string/myspace"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_myspace" />

        <com.szugyi.circlemenu.view.CircleImageView
            android:id="@+id/main_google_image"
            circle:name="@string/google"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_google" />

        <com.szugyi.circlemenu.view.CircleImageView
            android:id="@+id/main_linkedin_image"
            circle:name="@string/linkedin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_linkedin" />

        <com.szugyi.circlemenu.view.CircleImageView
            android:id="@+id/main_twitter_image"
            circle:name="@string/twitter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_twitter" />

        <com.szugyi.circlemenu.view.CircleImageView
            android:id="@+id/main_wordpress_image"
            circle:name="@string/wordpress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_wordpress" />
    </com.szugyi.circlemenu.view.CircleLayout>

    <TextView
        android:id="@+id/main_selected_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="50dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

 

旋转转盘选择Menu--第三方开源--CircleMenu

标签:

原文地址:http://www.cnblogs.com/zzw1994/p/5043733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!