zoukankan      html  css  js  c++  java
  • 拖动条SeekBar及星级评分条

    1.布局

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:orientation="vertical"
     6     tools:context=".AndroidSeekBarActivity" >
     7 
     8     <ImageView
     9         android:id="@+id/img"
    10         android:layout_width="match_parent"
    11         android:layout_height="240px"
    12         android:src="@drawable/mm" />
    13 
    14     <SeekBar
    15         android:id="@+id/sekbar"
    16         android:layout_width="match_parent"
    17         android:layout_height="wrap_content"
    18         android:max="255"
    19         android:progress="255"
    20         android:thumb="@drawable/sj" />
    21 
    22     <RatingBar
    23         android:id="@+id/ratbar"
    24         android:layout_width="match_parent"
    25         android:layout_height="wrap_content"
    26         android:max="255"
    27         android:numStars="5"
    28         android:progress="255"
    29         android:stepSize="0.5" />
    30 
    31 </LinearLayout>

    2.逻辑控制

     1 package com.example.androidseekbar;
     2 
     3 import android.os.Bundle;
     4 import android.app.Activity;
     5 import android.view.Menu;
     6 import android.widget.ImageView;
     7 import android.widget.RatingBar;
     8 import android.widget.RatingBar.OnRatingBarChangeListener;
     9 import android.widget.SeekBar;
    10 import android.widget.SeekBar.OnSeekBarChangeListener;
    11 
    12 public class AndroidSeekBarActivity extends Activity {
    13 
    14     @Override
    15     protected void onCreate(Bundle savedInstanceState) {
    16         super.onCreate(savedInstanceState);
    17         setContentView(R.layout.activity_android_seek_bar);
    18 
    19         final ImageView img = (ImageView) this.findViewById(R.id.img);
    20         SeekBar sekbar = (SeekBar) this.findViewById(R.id.sekbar);
    21         sekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    22 
    23             @Override
    24             public void onStopTrackingTouch(SeekBar seekBar) {
    25                 // TODO Auto-generated method stub
    26 
    27             }
    28 
    29             @Override
    30             public void onStartTrackingTouch(SeekBar seekBar) {
    31                 // TODO Auto-generated method stub
    32 
    33             }
    34 
    35             @Override
    36             public void onProgressChanged(SeekBar seekBar, int progress,
    37                     boolean fromUser) {
    38                 // 拖动时触发
    39                 img.setAlpha(progress);
    40             }
    41         });
    42         
    43         RatingBar ratbar=(RatingBar)this.findViewById(R.id.ratbar);
    44         ratbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
    45             
    46             @Override
    47             public void onRatingChanged(RatingBar arg0, float rating, boolean arg2) {
    48                 //动态改变图片透明度
    49                 img.setAlpha((int)(rating*255/5));
    50             }
    51         });
    52     }
    53 
    54     @Override
    55     public boolean onCreateOptionsMenu(Menu menu) {
    56         // Inflate the menu; this adds items to the action bar if it is present.
    57         getMenuInflater().inflate(R.menu.activity_android_seek_bar, menu);
    58         return true;
    59     }
    60 
    61 }

    作者:欢醉
    公众号【一个码农的日常】 技术群:319931204 1号群: 437802986 2号群: 340250479
    出处:http://zhangs1986.cnblogs.com/
    码云:https://gitee.com/huanzui
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    Top
  • 相关阅读:
    Spark RDD简介与运行机制概述
    MongoDB 3.0.6的主,从,仲裁节点搭建
    kafka入门:简介、使用场景、设计原理、主要配置及集群搭建(转)
    Spark配置参数调优
    SparkSQL项目中的应用
    SparkSQL相关语句总结
    Hadoop系统架构
    Hadoop常用命令
    spark单机模式简单搭建
    Spark参数配置说明
  • 原文地址:https://www.cnblogs.com/zhangs1986/p/2937157.html
Copyright © 2011-2022 走看看