动态布局加自定义样式时钟

<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" >
   <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>
</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;

public class MainActivity extends ActionBarActivity {
    private ToggleButton tog;
 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);
    }

}

用到的图片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值