zoukankan      html  css  js  c++  java
  • anroid 学习笔记18 ------ SeekBar 和 RatingBar

    废话不讲,上代码

    布局代码

    <RelativeLayout 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:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    /*可选择进度条*/
    <SeekBar
        android:id="@+id/two"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    
        android:max="500"
        />
    <TextView 
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/two"
        android:textColor="#ff0000"
        />
    /*星星进度条*/
    <RatingBar 
        android:id="@+id/xingxing"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/text"
        android:numStars="5"
        android:stepSize="0.5"
        />
    <TextView 
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/xingxing"
        android:textColor="#ff0000"
        />
    </RelativeLayout>

    java 代码

    package com.lihao.bar;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.RatingBar;
    import android.widget.RatingBar.OnRatingBarChangeListener;
    import android.widget.SeekBar;
    import android.widget.SeekBar.OnSeekBarChangeListener;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
        
        private SeekBar two;
        private TextView text;
        private RatingBar xingxing;
        private TextView text2;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);    
            
            text = (TextView)findViewById(R.id.text);
            text2 = (TextView)findViewById(R.id.text2);
            two = (SeekBar)findViewById(R.id.two);
            xingxing = (RatingBar)findViewById(R.id.xingxing);
            /*设置参数 绑定监听器*/
            two.setProgress(100);
            two.setSecondaryProgress(150);
            Barlistener listener = new Barlistener();
            two.setOnSeekBarChangeListener(listener);
            /*给xingxing绑定监听器*/
            Ratlistener rlistener = new Ratlistener();
            xingxing.setOnRatingBarChangeListener(rlistener);    
            
    }
    /**
     * 
     * @author Administrator
     *arg0 RatingBar对象
     *arg1 选中的星星的个数
     *arg2 是否是人为操作
     */
    class Ratlistener implements OnRatingBarChangeListener{
    
        @Override
        public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {
            // TODO Auto-generated method stub
            if(arg2)
            {
                text2.setText("我选了"+arg1+"颗星" );
            }
            
        }
        
    }
    /**
     * 
     * @author Administrator
     *arg0 SeekBar 对象
     *arg1  进度条的长度
     *arg2 是否人为操作
     */
    class Barlistener implements OnSeekBarChangeListener{
    
        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            // TODO Auto-generated method stub
            if(arg2)
            {
                text.setText("我的长度是:"+arg0.getProgress());
            }
                
        }
    
        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
            text.setText("帅哥你触摸了我");
        }
    
        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
            
        }
        
    }
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    }

    贴图

  • 相关阅读:
    asp.net 2.0-实现数据访问(1)
    跨平台跨服务器跨网站SSO(单点登录)方案的DEMO
    (翻译)Windows Communication Foundation (Workshop)-Part 2:在WCF中操作会话
    ipc的remoting
    忙活了半年的书已经交稿,年后就要出版
    一个ASP.NET2.0的小项目-BLOG
    (论坛答疑点滴)上传控件怎么修改样式?怎么设置readonly?
    【LoveCherry】上海.NET招聘!!!!!!!!!!!!!!!!!!!!!!!!!
    【翻译】Scott Mitchell的ASP.NET2.0数据指南中文版索引
    Scott Mitchell 的ASP.NET 2.0数据教程之二十四:: 分页和排序报表数据
  • 原文地址:https://www.cnblogs.com/lihaolihao/p/3224229.html
Copyright © 2011-2022 走看看