<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.bai.ToggleButtonORswitch.MainActivity" >
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.bai.ToggleButtonORswitch.MainActivity" >
<ToggleButton
android:id="@+id/toggle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textOff="横向排列"
android:textOn="纵向排列"
android:checked="true"/>
<Switch
android:id="@+id/sw"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textOff="横向排列"
android:textOn="纵向排列"
android:thumb="@drawable/check"
android:checked="true"
/>
<LinearLayout
android:id="@+id/text"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#f00"
android:textSize="10pt"
android:format12Hour="yyyy年MM月dd日 H:mma EEEE"/>
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dial="@drawable/watch"
android:hand_minute="@drawable/hand"></AnalogClock>
</LinearLayout>
android:id="@+id/toggle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textOff="横向排列"
android:textOn="纵向排列"
android:checked="true"/>
<Switch
android:id="@+id/sw"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textOff="横向排列"
android:textOn="纵向排列"
android:thumb="@drawable/check"
android:checked="true"
/>
<LinearLayout
android:id="@+id/text"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#f00"
android:textSize="10pt"
android:format12Hour="yyyy年MM月dd日 H:mma EEEE"/>
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dial="@drawable/watch"
android:hand_minute="@drawable/hand"></AnalogClock>
</LinearLayout>
</LinearLayout>
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.ToggleButton;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.ToggleButton;
public class MainActivity extends ActionBarActivity {
private ToggleButton tog;
private Switch sw;
private LinearLayout text;
private Switch sw;
private LinearLayout text;
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tog=(ToggleButton)findViewById(R.id.toggle);
sw=(Switch)findViewById(R.id.sw);
text=(LinearLayout)findViewById(R.id.text);
OnCheckedChangeListener list=new OnCheckedChangeListener() {
@SuppressLint("NewApi") @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO 自动生成的方法存根
if(isChecked){
//设置linearlayout垂直布局
tog.setChecked(true);
sw.setChecked(true);
text.setOrientation(1);
}else{
//设置linearlayout水平布局
tog.setChecked(false);
sw.setChecked(false);
text.setOrientation(0);
}
}
};
tog.setOnCheckedChangeListener(list);
sw.setOnCheckedChangeListener(list);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tog=(ToggleButton)findViewById(R.id.toggle);
sw=(Switch)findViewById(R.id.sw);
text=(LinearLayout)findViewById(R.id.text);
OnCheckedChangeListener list=new OnCheckedChangeListener() {
@SuppressLint("NewApi") @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO 自动生成的方法存根
if(isChecked){
//设置linearlayout垂直布局
tog.setChecked(true);
sw.setChecked(true);
text.setOrientation(1);
}else{
//设置linearlayout水平布局
tog.setChecked(false);
sw.setChecked(false);
text.setOrientation(0);
}
}
};
tog.setOnCheckedChangeListener(list);
sw.setOnCheckedChangeListener(list);
}
}
用到的图片