android开发之ToggleButton的用法实现
来源:互联网 发布:网络犯罪 编辑:程序博客网 时间:2024/05/16 14:24
代码根据老罗android开发视频教程中的思路,自己敲了一下,又搞定一个控件的用法。
学到的知识:
1、ToggleButton的用法
2、LinearLayout的嵌套布局方式。
UI_ToggleButtonActivity.java源码文件:
package com.jinhoward.UI_ToggleButton;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.CompoundButton;import android.widget.LinearLayout;import android.widget.ToggleButton;public class UI_ToggleButtonActivity extends Activity {private ToggleButton myToggleButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ui__toggle_button);myToggleButton=(ToggleButton)this.findViewById(R.id.togglebutton);final LinearLayout linearLayout = (LinearLayout)this.findViewById(R.id.buttonlayout);//设置监听器myToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){//1表示VERTICAL纵向布局linearLayout.setOrientation(1);}else {//0表示VERTICAL横向布局linearLayout.setOrientation(0);}}});}}
activity_ui__toggle_button.xml文件源代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ToggleButton android:id="@+id/togglebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:textOff="横向排列按钮" android:textOn="纵向排列按钮(默认)" > </ToggleButton> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/buttonlayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮2" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮3" /> </LinearLayout></LinearLayout>
效果图2张如下:
源码下载:http://download.csdn.net/detail/jinhoward/5672075
- android开发之ToggleButton的用法实现
- Android 控件开发之ToggleButton
- android开发之ToggleButton控件
- Android 控件开发之ToggleButton
- Android控件ToggleButton的用法
- Android ToggleButton控件的用法
- Android控件开发之ToggleButton原理
- android学习之ToggleButton实现开关效果
- Android开发ToggleButton控件的学习
- Android开发ToggleButton控件的学习
- Android开发ToggleButton控件的学习
- android开发中ToggleButton的使用方法详解
- Android的ToggleButton实现开关按钮
- Android之---两种自定义开关(ToggleButton)的实现(代码实现和图片实现)
- android学习之ToggleButton的使用
- Android开发:浅谈ToggleButton
- Android成长之路-Button、ImageButton、ToggleButton按钮的功能和用法
- Android自学笔记之ToggleButton(开关按钮)的功能、特殊属性、用法
- Multi-Attack Web Method
- 笔记:oracle常见问题
- mci应用
- 一次由重复索引导致的问题
- 关于Android发送短信字数问题的分析及解决方法
- android开发之ToggleButton的用法实现
- 【追寻javascript高手之路04】理解prototype
- eth_type_trans的处理流程图
- C#查看各种变量的指针地址
- Cyclical Quest CF235C
- 14-判断字符串中是否有英文(字符串处理)
- 并发场景下HashMap.get导致cpu耗光
- Android中如何修改系统时间(应用程序获得系统权限)
- NYOJ92-图像有用区域