Android 圆形遥控器按钮盘 带中间按钮
链接:https://blog.csdn.net/sinat_38184748/article/details/89182372
版本1.0.7已改成androidx+kotlin代码,如有appcompat-v7的需求,请使用1.0.6版本。
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.D10NGYANG:DL10RoundMenuView:1.0.9'
}
<com.dlong.rep.dlroundmenuview.DLRoundMenuView
android:id="@+id/dl_rmv"
android:layout_width="200dp"
android:layout_height="200dp"
app:RMCoreMenuDrawable="@mipmap/circle"
app:RMRoundMenuDrawable="@mipmap/go"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
布局中
app:RMHasCoreMenu="true"
代码中
dlRoundMenuView.setHasCoreMenu(true);
布局中
app:RMCoreMenuNormalBackgroundColor="#ffffffff"
代码中
dlRoundMenuView.setCoreMenuNormalBackgroundColor(0xffffffff);
布局中
app:RMCoreMenuStrokeColor="#cc999999"
代码中
dlRoundMenuView.setCoreMenuStrokeColor(0xcc999999);
布局中
app:RMCoreMenuStrokeSize="1dp"
代码中
dlRoundMenuView.setCoreMenuStrokeSize(2.0f);
布局中
app:RMCoreMenuSelectedBackgroundColor="#cc999999"
代码中
dlRoundMenuView.setCoreMenuSelectedBackgroundColor(0xcc999999);
布局中
app:RMCoreMenuDrawable="@mipmap/circle"
代码中
dlRoundMenuView.setCoreMenuDrawable(mContext.getResources().getDrawable(R.mipmap.circle));
布局中
app:RMCoreMenuRoundRadius="50dp"
代码中
dlRoundMenuView.setCoreMenuRoundRadius(50f);
布局中
app:RMRoundMenuNumber="4"
代码中
dlRoundMenuView.setRoundMenuNumber(4);
布局中
app:RMRoundMenuDeviationDegree="45"
代码中
dlRoundMenuView.setRoundMenuDeviationDegree(45f);
统一图片即可,程序里有旋转处理 布局中
app:RMRoundMenuDrawable="@mipmap/go"
代码中 可单独设定每个位置的图片,0代表位置0,如果是4个菜单的话就是正上方的位置。
dlRoundMenuView.setRoundMenuDrawable(0,mContext.getResources().getDrawable(R.mipmap.go));
布局中
app:RMIsDrawLineToCenter="false"
代码中
dlRoundMenuView.setIsDrawLineToCenter(false);
布局中
app:RMIsDrawLineToCenter="false"
代码中
dlRoundMenuView.setIsDrawLineToCenter(false);
布局中
app:RMRoundMenuNormalBackgroundColor="@color/white"
代码中
dlRoundMenuView.setRoundMenuNormalBackgroundColor(0xffffffff);
布局中
app:RMRoundMenuSelectedBackgroundColor="#cc999999"
代码中
dlRoundMenuView.setRoundMenuSelectedBackgroundColor(0xcc999999);
布局中
app:RMRoundMenuStrokeColor="#cc999999"
代码中
dlRoundMenuView.setRoundMenuStrokeColor(0xcc999999);
布局中
app:RMRoundMenuStrokeSize="1dp"
代码中
dlRoundMenuView.setRoundMenuStrokeSize(2f);
布局中
app:RMRoundMenuDistance="80%"
代码中
dlRoundMenuView.setRoundMenuDistance(0.8f);
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
// 单击
binding.dlRmv.setOnMenuClickListener(object : OnMenuClickListener {
override fun OnMenuClick(position: Int) {
//Toast.makeText(mContext, "点击了:"+position,Toast.LENGTH_SHORT).show();
Log.i("单击", "点击了:$position")
}
})
// 长按
binding.dlRmv.setOnMenuLongClickListener(object : OnMenuLongClickListener{
override fun OnMenuLongClick(position: Int) {
Log.i("长按", "点击了:$position")
}
})
// 触摸
binding.dlRmv.setOnMenuTouchListener(object : OnMenuTouchListener {
override fun OnTouch(event: MotionEvent?, position: Int) {
Log.v("触摸", "事件=${event.toString()}")
Log.d("触摸", "位置=$position")
}
})
// 统一lambda接口
binding.dlRmv.setOnMenuListener {
onMenuClick { position ->
// 单击
Log.i("lambda 单击", "点击了:$position")
}
onMenuLongClick { position ->
// 长按
Log.i("lambda 长按", "点击了:$position")
}
onTouch { event, position ->
// 触摸
Log.v("lambda 触摸", "事件=${event.toString()}")
Log.d("lambda 触摸", "位置=$position")
}
}
}
}
-keep class com.dlong.rep.dlroundmenuview.** {*;}
-dontwarn com.dlong.rep.dlroundmenuview.**