Skip to content

Commit

Permalink
+修改小问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjay-F committed Jan 14, 2016
1 parent e11bef7 commit 3365c3b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
9 changes: 6 additions & 3 deletions app/src/main/java/com/xk/sanjay/rulerview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.xk.sanjay.rulberview.RulerWheel;

Expand All @@ -12,16 +12,19 @@ public class MainActivity extends AppCompatActivity {
private RulerWheel rulerView;
private String TAG = this.getClass().getSimpleName();

private TextView tvCurValue;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tvCurValue = (TextView) findViewById(R.id.curValue_tv);
rulerView = (RulerWheel) findViewById(R.id.ruler_view);
rulerView.setScrollingListener(new RulerWheel.OnWheelScrollListener() {
@Override
public void onChanged(RulerWheel wheel, int oldValue, int newValue) {
Log.e(TAG, "curValue=" + newValue);
public void onChanged(RulerWheel wheel, int oldValue, final int newValue) {
tvCurValue.setText(newValue+"");
}

@Override
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.xk.sanjay.rulerview.MainActivity">


<TextView
android:id="@+id/curValue_tv"
android:text="20"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="50dp"
android:textSize="20sp"
android:textColor="#ff0989"/>

<com.xk.sanjay.rulberview.RulerWheel
android:id="@+id/ruler_view"
android:layout_width="match_parent"
android:layout_height="400dp"

app:MaxBarSize="3dp"
app:MidBarSize="2dp"
app:MaxBarSize="2dp"
app:MidBarSize="1.5dp"
app:MinBarSize="1dp"

app:alignMode="UP"
app:alignMode="DOWN"

app:def_value="40"
app:lineColorMax="#797979"
Expand All @@ -33,14 +39,12 @@
app:lineColorMin="#797979"
app:line_divider="10dp"


app:mask_bg="@mipmap/icon_arrow"
app:max_value="100"
app:min_value="20"
app:mode="SCALE"

app:scaleWidth="1dp"


app:showGradient="true"
app:showScaleValue="true"
app:text_Size="30"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
classpath 'com.android.tools.build:gradle:1.5.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
1 change: 0 additions & 1 deletion rulberview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.text.Layout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

Expand All @@ -21,7 +20,7 @@
* Description: 参考自: http://blog.csdn.net/dashu8193058/article/details/45846189
*/
public class RulerWheel extends View {
private String TAG = this.getClass().getSimpleName();
// private String TAG = this.getClass().getSimpleName();
// 默认刻度模式
public static final int MOD_TYPE_SCALE = 5;
// 1/2模式
Expand Down Expand Up @@ -334,8 +333,8 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (w == 0 || h == 0)
return;
int rHeight = h - getPaddingTop() - getPaddingBottom();
mLineHeighMax = rHeight / 2;
mLineHeighMid = rHeight / 3;
mLineHeighMax = rHeight / 3;
mLineHeighMid = rHeight / 4;
mLineHeighMin = rHeight / 7;
}

Expand Down Expand Up @@ -496,7 +495,7 @@ private void drawDownMode(Canvas canvas, int halfCount, int distanceX, int currV
int value;
float xPosition;

Log.e(TAG, " halfCount=" + halfCount + " rWidth" + rWidth);
// Log.e(TAG, " halfCount=" + halfCount + " rWidth" + rWidth);
//线y坐标
int ry = (int) (rHeight - mTpDesiredWidth - textPaint.getTextSize()) - getPaddingBottom();
for (int i = 0; i < halfCount; i++) {
Expand All @@ -506,7 +505,7 @@ private void drawDownMode(Canvas canvas, int halfCount, int distanceX, int currV
xPosition = rWidth / 2f + i * mLineDivder + distanceX;
value = currValue + i;
if (xPosition <= rWidth && value >= mMinValue && value <= mMaxValue) {
Log.e(TAG, "right value=" + value + " xPos=" + xPosition);
// Log.e(TAG, "right value=" + value + " xPos=" + xPosition);
if (value % mModType == 0) {
if (mModType == MOD_TYPE_HALF) {
linePaint.setColor(mLineColorMax);
Expand Down Expand Up @@ -552,7 +551,7 @@ private void drawDownMode(Canvas canvas, int halfCount, int distanceX, int currV
xPosition = rWidth / 2f - i * mLineDivder + distanceX;
value = currValue - i;
if (xPosition > getPaddingLeft() && value >= mMinValue && value <= mMaxValue) {
Log.e(TAG, "left value=" + value);
// Log.e(TAG, "left value=" + value);
if (value % mModType == 0) {
if (mModType == MOD_TYPE_HALF) {
linePaint.setColor(mLineColorMax);
Expand Down

0 comments on commit 3365c3b

Please sign in to comment.