ToggleButton, Status Select button, can display the layout dynamically

Source: Internet
Author: User

Mainactivity.java

1 publicclassmainactivityextendsactivity{2 @Override3 protectedvoid onCreate (Bundle savedinstancestate) {4 super.oncreate (savedinstancestate);5 Setcontentview (r.layout.activity_main);6ToggleButton ToggleButton =(ToggleButton) Findviewbyid (R.ID.TOG_BTN);7Finallinearlayout layout =(LinearLayout) Findviewbyid (r.id.text);8       Togglebutton.setoncheckedchangelistener (Newoncheckedchangelistener () {9         @OverrideTen         publicvoid oncheckedchanged (Compoundbutton Buttonview,Boolean isChecked) { A           //TODO auto-generated Method Stub -           if(isChecked) { -Layout.setorientation (1); the}Else{ -Layout.setorientation (0); -           } -         } +       }); -     } +}            

Layout FileActivity_main.xml
  1. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:id="@+id/text0"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical"
  7. tools:context=".MainActivity">
  8. <ToggleButton
  9. android:id="@+id/tog_btn"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:checked="true"
  13. android:textOff="横向"
  14. android:textOn="纵向"/>
  15. <LinearLayout
  16. android:id="@+id/text"
  17. android:layout_width="match_parent"
  18. android:layout_height="match_parent"
  19. android:orientation="vertical">
  20. <Button
  21. android:id="@+id/btn1"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"/>
  24. <Button
  25. android:id="@+id/btn2"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"/>
  28. <Button
  29. android:id="@+id/btn3"
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"/>
  32. </LinearLayout>
  33. </LinearLayout>

ToggleButton, Status Select button, can display the layout dynamically

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.