AnalogClock、ToggleButton、Switch、RatingBar、SeekBar

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <AnalogClock
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="选择开关:" />

            <ToggleButton
                android:id="@+id/togglebutton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="false"
                android:textOff="关闭"
                android:textOn="开启" />

            <Switch
                android:id="@+id/sw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:textOff="关闭"
                android:textOn="开启" />

            <TextView
                android:id="@+id/textts"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/background_dark"
                android:textSize="20sp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#000000" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingTop="20dp"
                android:text="打分" />

            <RatingBar
                android:id="@+id/ratingbar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:max="6"
                android:numStars="6"
                android:progress="2"
                android:stepSize="0.5" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#000000" />

            <TextView
                android:id="@+id/textrb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <ImageView
                android:id="@+id/img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/ic_launcher" />

            <SeekBar
                android:id="@+id/seekbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:max="255"
                android:progress="255" />

            <TextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Switch;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
import android.widget.ToggleButton;

public class MainActivity extends Activity {

    private ImageView img;
    private SeekBar seekbar;
    private TextView text;
    private RatingBar ratingbar;
    private TextView textratingbar;
    private ToggleButton togglebutton;
    private Switch sw;
    private TextView textts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img=(ImageView)findViewById(R.id.img);
        seekbar=(SeekBar)findViewById(R.id.seekbar);
        text=(TextView)findViewById(R.id.text);
        //text可以滚动
        text.setMovementMethod(ScrollingMovementMethod.getInstance());
        seekbar.setOnSeekBarChangeListener(new MyOnSeekBarChange());
        //SeekBar拖动条事件结束
        //SeekBar评分开始
        ratingbar=(RatingBar)findViewById(R.id.ratingbar);
        textratingbar=(TextView)findViewById(R.id.textrb);
        ratingbar.setOnRatingBarChangeListener(new MyOnRatingBarChang());
        //状态开关
        togglebutton=(ToggleButton)findViewById(R.id.togglebutton);
        sw=(Switch)findViewById(R.id.sw);
        textts=(TextView)findViewById(R.id.textts);
        togglebutton.setOnCheckedChangeListener(new MyOnCheckedChangeListener());
        sw.setOnCheckedChangeListener(new MyOnCheckedChangeListener());

    }
    /**
     * SeekBar拖动条事件
     * @author Administrator
     *
     */
    private class MyOnSeekBarChange  implements OnSeekBarChangeListener{

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub
            text.append("显示中:"+seekBar.getProgress()+"\n");
            //设置透明度
            img.setImageAlpha(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
            text.append("开始"+"\n");
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
            text.append("结束"+"\n");
        }

    }
    /**
     * SeekBar评分
     * @author Administrator
     *
     */
    private class MyOnRatingBarChang implements OnRatingBarChangeListener{

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                boolean fromUser) {
            // TODO Auto-generated method stub
            textratingbar.setText("用户评分:"+rating);
        }

    }
    /**
     * ToggleButton  Switch状态开关
     * @author Administrator
     *
     */
    private class MyOnCheckedChangeListener implements OnCheckedChangeListener{

        @Override
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            if (isChecked) {
                textts.setText("您的选择是:开");
            }else {
                textts.setText("您的选择是:关");
            }
        }


    }


}

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值