拖动条实例与星级评分条制作

拖动条实例与星级评分条制作,第1张

概述(一)拖动实例之美图秀秀修改透明度在垂直的线性布局管理器中添加两个图像视图,在添加一个Seekbar拖动条,设置最大值max和progress,并设置id给Image和seekbar。在主程序中,获取image变量和seekbar变量,并通过seekbar的setOnSeekBarChangeListener来设置image的setImageAlpha(progress)

(一)拖动条实例之美图秀秀修改透明度

在垂直的线性布局管理器中添加两个图像视图,在添加一个Seekbar拖动条,设置最大值max和progress,并设置ID给Image和seekbar。

在主程序中,获取image变量和seekbar变量,并通过seekbar的setonSeekbarchangelistener来设置image的se@R_403_5411@Alpha(progress);

布局文件:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:orIEntation="vertical"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".MainActivity">    <ImageVIEw        androID:ID="@+ID/image"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:src="@drawable/lijiang" />    <Seekbar        androID:ID="@+ID/seekbar"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:max="255"        androID:progress="255" />    <ImageVIEw        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:scaleType="fitXY"        androID:src="@drawable/meitu" /></linearLayout>

主程序文件:

package com.example.seekbar;import androIDx.annotation.RequiresAPI;import androIDx.appcompat.app.AppCompatActivity;import androID.os.Build;import androID.os.Bundle;import androID.Widget.ImageVIEw;import androID.Widget.Seekbar;import androID.Widget.Toast;public class MainActivity extends AppCompatActivity {    private Seekbar seekbar;    private ImageVIEw image;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        seekbar=(Seekbar)findVIEwByID(R.ID.seekbar);        image=(ImageVIEw)findVIEwByID(R.ID.image);        seekbar.setonSeekbarchangelistener(new Seekbar.OnSeekbarchangelistener() {            @RequiresAPI(API = Build.VERSION_CODES.JELLY_BEAN)            @OverrIDe            public voID onProgressChanged(Seekbar seekbar, int progress, boolean fromUser) {                image.se@R_403_5411@Alpha(progress);            }            @OverrIDe            public voID onStartTrackingtouch(Seekbar seekbar) {            }            @OverrIDe            public voID onStopTrackingtouch(Seekbar seekbar) {            }        });    }}

程序截图:

 

 

(二)星级评分

androID:isIndicator:是否用作指示,用户无法更改,默认falseandroID:numStars:显示多少个星星,必须为整数androID:rating:默认评分值,必须为浮点数androID:stepSize: 评分每次增加的值,必须为浮点数Onratingbarchangelistener //事件处理

只做一个淘宝评分条
首先导入背景图片,再加一个textvIEw文字,加一个button按钮来判断当前的星星个数,其次再加一个ratingbar
在主程序中,通过获取button对象,用他的点击事件来显示ratingbar的rating值,通过字符串来进行显示。
布局文件:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@drawable/xing1"    tools:context=".MainActivity">    <TextVIEw        androID:ID="@+ID/textVIEw"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_above="@+ID/btn"        androID:layout_marginBottom="202dp"        androID:text="@string/score"        androID:textSize="20sp" />    <ratingbar        androID:ID="@+ID/ratingbar"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_above="@+ID/btn"        androID:layout_marginBottom="128dp"        androID:numStars="5"        androID:rating="5" />    <button        androID:ID="@+ID/btn"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentBottom="true"        androID:layout_alignParentRight="true"        androID:background="#FF5000"        androID:text="@string/Pingjia" /></relativeLayout>

主程序文件:

package com.example.ratingbar;import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.ratingbar;import androID.Widget.Toast;public class MainActivity extends AppCompatActivity {    private ratingbar ratingbar;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        ratingbar=(ratingbar)findVIEwByID(R.ID.ratingbar);        button button=(button)findVIEwByID(R.ID.btn);        button.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                float rating=ratingbar.getrating();                Toast.makeText(MainActivity.this,"你得到了"+rating+"颗星",Toast.LENGTH_SHORT).show();            }        });    }}

程序截图:

 

 

 

 
总结

以上是内存溢出为你收集整理的拖动条实例与星级评分条制作全部内容,希望文章能够帮你解决拖动条实例与星级评分条制作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1065305.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存