基于Android实现转盘按钮代码

时间:2021-05-19

先给大家展示下效果图:

package com.lixu.circlemenu; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.Toast; import com.lixu.circlemenu.view.CircleImageView; import com.lixu.circlemenu.view.CircleLayout; import com.lixu.circlemenu.view.CircleLayout.OnItemClickListener; import com.lixu.circlemenu.view.CircleLayout.OnItemSelectedListener; import com.szugyi.circlemenu.R; 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(); } }

引用两个开源类:

package com.lixu.circlemenu.view; /* * Copyright Csaba Szugyiczki * * Licensed under the Apache License, Version . (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://.lixu.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="dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

基于Android实现转盘按钮代码的全部内容就到此结束了,希望能够帮助到大家。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章