Radiogroup Implementing a segmented selection (Uisegmentedcontrol) control similar to iOS

Source: Internet
Author: User

In iOS7, there is a flat-style control called a segmented selection control Uisegmentedcontrol, the control is divided into a row, a few buttons that are separated by simple lines, each click can only select one of the buttons, he is similar to Tabbar but slightly different, The new QQ mobile phone client uses this kind of control.

However, there are no ready-made controls available on Android, but Radiogroup controls that have similar features in Android and have very different UI can achieve the same purpose by defining the appearance of the Radiogroup. In fact, there is no Tabbar Android, but many apps by modifying the Radiogroup to achieve the Uitabbar effect in iOS, it seems that Radiogroup is really a very useful control, although the original is really ugly.

Novice Radiogroup customization may be difficult to do, Git has a ready-made library and examples, you can download learning, if you are a project developed with Eclipse, you may need to change to use, because he provides the project structure of Android Studio.

Project Address: Https://github.com/hoang8f/android-segmented-control

Use:

<?xml version="1.0"encoding="Utf-8"? ><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"Android:layout_width="match_parent"Android:layout_height="match_parent"Android:background="@color/content_backgroud"android:orientation="Vertical"> <info.hoang8f.android.segmented.segmentedgroup xmlns:segmentedgroup="Http://schemas.android.com/apk/res-auto"Android:id="@+id/segmented2"Android:layout_width="match_parent"Android:layout_height="wrap_content"Android:background="@color/white"android:orientation="Horizontal"android:padding="10DP"Segmentedgroup:sc_border_width="1.5DP"Segmentedgroup:sc_corner_radius="5DP"> <RadioButton Android:id="@+id/question_hot"style="@style/segmentradiobutton"Android:layout_width="0DP"Android:layout_height="wrap_content"Android:layout_weight="1"Android:paddingbottom="7DP"Android:paddingtop="7DP"Android:text="Top Questions"android:textsize="16sp"/> <RadioButton Android:id="@+id/question_category"style="@style/segmentradiobutton"Android:layout_width="0DP"Android:layout_height="wrap_content"Android:layout_weight="1"Android:paddingbottom="7DP"Android:paddingtop="7DP"Android:text="Classification Issues"android:textsize="16sp"/> </info.hoang8f.android.segmented.SegmentedGroup> <framelayout android:layout_margintop="10DP"Android:id="@+id/rl_container"Android:layout_width="match_parent"Android:layout_height="match_parent"/></linearlayout>

@Override Public voidOnClick (View v) {basefragment fragment=NULL; Switch(V.getid ()) { Caser.id.question_hot:fragment=questionhotfragment.newinstance ();  Break;  Caser.id.question_category:fragment=questioncategoryfragment.newinstance ();  Break; default:             Break; }    if(Fragment! =NULL) {Fragmentmanager Fragmentmanager=Getsupportfragmentmanager (); Fragmenttransaction Transaction=fragmentmanager.begintransaction ();        Transaction.replace (R.id.rl_container, fragment);    Transaction.commit (); }}

Radiogroup Implementing a segmented selection (Uisegmentedcontrol) control similar to iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.