标签:


<ToggleButtonandroid:id="@+id/togglebutton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"android:textOn="横向排列"android:textOff="纵向排列"/>
<Switchandroid:id="@+id/swichd"android:showText="true"android:splitTrack="true"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textOff="纵向排列"android:textOn="横向排列">
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/Mylayout"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按键1"/><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按键2"/><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按键3"/></LinearLayout>
....toggleButton = (ToggleButton)findViewById(R.id.togglebutton);aSwitch = (Switch)findViewById(R.id.swichd);final LinearLayout linearLayout = (LinearLayout)findViewById(R.id.Mylayout);aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Override- // Switch按键状态变换时触发按钮
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(buttonView.isChecked()){linearLayout.setOrientation(LinearLayout.HORIZONTAL); //竖直}else{linearLayout.setOrientation(LinearLayout.VERTICAL); //竖直}}});- // ToggleButon 按键状态改变触发按钮
toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(buttonView.isChecked()){linearLayout.setOrientation(LinearLayout.HORIZONTAL); //竖直}else{linearLayout.setOrientation(LinearLayout.VERTICAL); //竖直}}});

Android 学习笔记(4)—— ToggleButton 、Switch
标签:
原文地址:http://www.cnblogs.com/shaorui/p/5206540.html