Android中的ToggleButton
来源:互联网 发布:淘宝卖家千牛工作台 编辑:程序博客网 时间:2024/06/06 01:26
这个小例子主要用来演示ToggleButton的基本使用。效果大致是一开始界面是垂直布局的,当点击ToggleButton按钮的时候,布局变为水平方向的
大致的代码贴一下吧,其中main.xml代码如下:
<?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() {@Overridepublic void onCheckedChanged(CompoundButton arg0, boolean arg1) {if(arg1){//设置垂直布局layout.setOrientation(1);}else{//设置水平布局layout.setOrientation(0);}}}); }}
0 0
- Android中的ToggleButton
- android中的ToggleButton
- android 中的ToggleButton组件应用
- 关于Android中的 ToggleButton 组件 (待续)
- android中的ImageButton,RadioGroup,CheckBox,ToggleButton
- Android中的ToggleButton和Switch开关控件
- android ToggleButton
- Android-ToggleButton
- Android ToggleButton example
- Android开关控件ToggleButton
- android控件之ToggleButton
- android ToggleButton的使用
- Android--ToggleButton控件
- Android 自定义ToggleButton
- Android-ToggleButton&CheckTextView&CheckBox
- Android ToggleButton和Switch
- android-----自定义ToggleButton
- 学Android---ToggleButton
- QT学习之路
- Excel-时间序列图(趋势)分析
- UFLDL学习笔记6(Linear Decoders with Autoencoders)
- latex写论文
- 在java项目中配置web service服务
- Android中的ToggleButton
- 盗版XP成主要恶意攻击对象
- 2073 活动选择问题【贪心】
- 总结java方法(函数)传值和传引用的问题
- LeetCode OJ:Palindrome Partitioning II
- jQuery-强大的jQuery选择器 (详解)
- POJ2063 Investment
- (七)中缀表达式转换后缀表达式算法
- 计算机图形学入门学习——阴影