android中ToggleButton的使用
2012-05-17 12:44
246 查看
这个小例子主要用来演示ToggleButton的基本使用。效果大致是一开始界面是垂直布局的,当点击ToggleButton按钮的时候,布局变为水平方向的
大致的代码贴一下吧,其中main.xml代码如下:
AndroidDemo4Activity.java代码如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:textOff="横向排列" android:textOn="纵向排列" /> <LinearLayout android:id="@+id/lLayout" 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="Button" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> </LinearLayout>
AndroidDemo4Activity.java代码如下:
package android.demo; import android.app.Activity; import android.os.Bundle; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.LinearLayout; import android.widget.ToggleButton; public class AndroidDemo4Activity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ToggleButton toggle=(ToggleButton)findViewById(R.id.toggleButton1); final LinearLayout layout=(LinearLayout)findViewById(R.id.lLayout); toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { if(arg1){ //设置垂直布局 layout.setOrientation(1); }else{ //设置水平布局 layout.setOrientation(0); } } }); } }
相关文章推荐
- android开发中ToggleButton的使用方法详解
- android:onClick属性使用之ToggleButton
- Android—ToggleButton、Switch和RatingBar使用
- Android使用SharedPreferences实现本地轻量存储,ToggleButton,TextView边框详解
- Android控件ToggleButton的使用与修改
- 【Android 开发】:UI控件之开关状态按钮 ToggleButton 的使用方法
- android中使用自定义控件checkbox,ToggleButton,ProgressBar
- Android成长日记-使用ToggleButton实现灯的开关
- [Android UI]基础组件的学习——ToggleButton的使用及样式修改
- [Android实例] eoe & 友盟教程大赛【ToggleButton使用教程】
- android 使用ToggleButton实现开关效果
- Android ToggleButton使用介绍
- 在Android中使用并发来提高速度和性能
- 基于mini2440嵌入式linux上整合一套Domoticz智能家居系统(九)使用domoticz+mosquitto+Android客户端实现控制mini2440上的LED(二)
- android的toogleButton和switch的使用方法
- android Google 应用(二) -Google Map 的使用-
- Android 之 下拉框(Spinner)的使用
- Android中的隐藏API和Internal包的使用之获取应用电量排行
- android建立工程及使用Tabhost
- Android中<meta-data>的使用