类似iOS的Segment Control控件
xml:
<com.simple.widgets.SegmentView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_gravity="top|center" android:layout_margin="10dp" android:background="@drawable/segment_shape" android:gravity="center" android:orientation="horizontal" /> java: SegmentView rGroup = (SegmentView) findViewById(R.id.rg); // 默认为横向排列,如上图所示,如需纵向排列请调用setOrientation方法 // rGroup.setOrientation(SegmentView.VERTICAL); // 设置tabs rGroup.setTabs(new String[] { "主页", "朋友圈", "搜索" }); // 设置点击事件 rGroup.setOnItemCheckedListener(new OnItemCheckedListener() { @Override public void onCheck(RadioButton button, int position, String title) { Toast.makeText(getApplicationContext(), "checked id = " + position + ", title = " + title, Toast.LENGTH_SHORT).show(); } }); GitHub地址:https://github.com/hehonghui/SegmentView
SegmentView rGroup = (SegmentView) findViewById(R.id.rg); // 默认为横向排列,如上图所示,如需纵向排列请调用setOrientation方法 // rGroup.setOrientation(SegmentView.VERTICAL); // 设置tabs rGroup.setTabs(new String[] { "主页", "朋友圈", "搜索" }); // 设置点击事件 rGroup.setOnItemCheckedListener(new OnItemCheckedListener() { @Override public void onCheck(RadioButton button, int position, String title) { Toast.makeText(getApplicationContext(), "checked id = " + position + ", title = " + title, Toast.LENGTH_SHORT).show(); } }); GitHub地址:https://github.com/hehonghui/SegmentView
尊敬的会员,只需要简单地分享到微信、QQ空间、微薄等,就可以轻松地获得获得下载积分免费下载、发布任务啦,详细见推广规则。