标签:tool 按钮 动态 hang family listen generate icc line
MainActivity.java
1 publicclassMainActivityextendsActivity{
2 @Override
3 protectedvoid onCreate(Bundle savedInstanceState){
4 super.onCreate(savedInstanceState);
5 setContentView(R.layout.activity_main);
6 ToggleButton toggleButton =(ToggleButton)findViewById(R.id.tog_btn);
7 finalLinearLayout layout =(LinearLayout) findViewById(R.id.text);
8 toggleButton.setOnCheckedChangeListener(newOnCheckedChangeListener(){
9 @Override
10 publicvoid onCheckedChanged(CompoundButton buttonView,boolean isChecked){
12 // TODO Auto-generated method stub
13 if(isChecked){
14 layout.setOrientation(1);
15 }else{
16 layout.setOrientation(0);
17 }
18 }
19 });
20 }
21 }
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ToggleButton
android:id="@+id/tog_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textOff="横向"
android:textOn="纵向"/>
<LinearLayout
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
标签:tool 按钮 动态 hang family listen generate icc line
原文地址:http://www.cnblogs.com/lhgyuyu/p/6189655.html