位置好,身高体重怎么计算公式设置

百度拇指医生
&&&普通咨询
您的网络环境存在异常,
请输入验证码
验证码输入错误,请重新输入Android自定义标尺控件(选择身高、体重等) - 简书
Android自定义标尺控件(选择身高、体重等)
自定义view学习(第一章)
1、自定义刻度尺控件
在我们想要获取用户的身高体重等信息时,直接让他们输入显然不够友好偶然看到一款App用了类似刻度尺的界面让用户选择,觉得很赞。所有决定实现下。
实现的最终效果如下图所示:
7c0d6b-d14f3097.gif
2、使用方式
2.1 在gradle添加依赖
compile 'com.zkk.view:ZkkRulerView:1.0.0'
2.2 在xml中设置
&com.zkk.view.rulerview.RulerView
android:id="@+id/ruler_height"
android:layout_width="fill_parent"
android:layout_height="58.0dip"
android:layout_marginTop="24.0dip"
app:alphaEnable="true"
app:lineColor="@color/gray"
app:lineMaxHeight="40dp"
app:lineMidHeight="30dp"
app:lineMinHeight="20dp"
app:lineSpaceWidth="10dp"
app:lineWidth="2dip"
app:textColor="@color/black"
app:minValue="80.0"
app:maxValue="250.0"
app:perValue="1"
app:selectorValue="165.0"
2.3 在activity中只需调用一个方法和一个数值的回调
ruler_height=(RulerView)findViewById(R.id.ruler_height);
ruler_weight.setOnValueChangeListener(new RulerView.OnValueChangeListener() {
public void onValueChange(float value) {
tv_register_info_weight_value.setText(value+"");
* @param selectorValue 未选择时 默认的值 滑动后表示当前中间指针正在指着的值
* @param minValue
* @param maxValue
最小的数值
* @param per
如 1:表示 每2条刻度差为1.
0.1:表示 每2条刻度差为0.1 在demo中 身高mPerValue为1
体重mPerValue 为0.1
ruler_weight.setValue(165, 80, 250, 1);
2、实现讲解
首先先无耻的将github地址抛出:
android:id="@+id/tv_register_info_height_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11.0dip"
android:includeFontPadding="false"
android:maxHeight="24.0sp"
android:text="165"
android:textColor="#cc222222"
android:textSize="24.0sp"/&
&RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"&
&com.zkk.view.RulerView
android:id="@+id/ruler_height"
android:layout_width="fill_parent"
android:layout_height="58.0dip"
android:layout_marginTop="24.0dip"/&
&ImageView
android:layout_width="14.0dip"
android:layout_height="46.0dip"
android:layout_centerHorizontal="true"
android:layout_marginTop="11.0dip"
android:scaleType="fitXY"
android:src="@drawable/user_info_ruler_height"/&
&/RelativeLayout&
自定义了一个 RulerView。代码就不一一写出,在源码中有详细的解释。
private int mMinV
private Scroller mS
//Scroller是一个专门用于处理滚动效果的工具类
用mScroller记录/计算View滚动的位置,再重写View的computeScroll(),完成实际的滚动
private VelocityTracker mVelocityT //主要用跟踪触摸屏事件(flinging事件和其他gestures手势事件)的速率。
private int mW
private int mH
private float mSelectorValue = 50.0f; // 未选择时 默认的值 滑动后表示当前中间指针正在指着
private float mMaxValue = 200;
// 最大数值
private float mMinValue = 100.0f;
//最小的数值
private float mPerValue = 1;
//最小单位
如 1:表示 每2条刻度差为1.
0.1:表示 每2条刻度差为0.1
// 在demo中 身高mPerValue为1
体重mPerValue 为0.1
private float mLineSpaceWidth = 5;
尺子刻度2条线之间的距离
private float mLineWidth = 4;
尺子刻度的宽度
private float mLineMaxHeight = 420;
尺子刻度分为3中不同的高度。 mLineMaxHeight表示最长的那根(也就是 10的倍数时的高度)
private float mLineMidHeight = 30;
mLineMidHeight
表示中间的高度(也就是 5
15 25 等时的高度)
private float mLineMinHeight = 17;
mLineMinHeight
表示最短的那个高度(也就是 1 2 3 4 等时的高度)
private float mTextMarginTop = 10;
private float mTextSize =30;
//尺子刻度下方数字 textsize
private boolean mAlphaEnable =
// 尺子 最左边 最后边是否需要透明 (透明效果更好点)
private float mTextH
//尺子刻度下方数字
private Paint mTextP
// 尺子刻度下方数字( 也就是每隔10个出现的数值) paint
private Paint mLineP
private int mTotalL
//共有多少条 刻度
private int mMaxO
//所有刻度 共有多长
private float mO
// 默认状态下,mSelectorValue所在的位置
位于尺子总刻度的位置
private int mLastX, mM
private OnValueChangeListener mL
// 滑动后数值回调
github地址:

我要回帖

更多关于 设置网络位置选哪个好 的文章

 

随机推荐