Skip to content

Commit bcdf792

Browse files
author
Kaler
committed
Fix bugs of Slider
1 parent ae56f44 commit bcdf792

File tree

8 files changed

+16
-17
lines changed

8 files changed

+16
-17
lines changed

MaterialDesign/src/com/gc/materialdesign/utils/Utils.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.gc.materialdesign.utils;
22

33
import android.content.res.Resources;
4+
import android.graphics.Rect;
45
import android.util.TypedValue;
56
import android.view.View;
6-
import android.view.ViewGroup;
77

88
public class Utils {
99

@@ -35,17 +35,13 @@ public static float dipOrDpToFloat(String value) {
3535
/**
3636
* 这里看似是得到控件相对的坐标,但是如果这个滑动条在可以上下滚动的布局中就会出现问题。
3737
* 因为这里的坐标都是死的,在上下滚动的view中父控件的top仍旧不变,但实际上是应该获得动态数值的。
38-
* @error
3938
* @param myView
4039
* @return
4140
*/
4241
public static int getRelativeTop(View myView) {
43-
// if (myView.getParent() == myView.getRootView())
44-
myView.getParent().requestLayout();
45-
if(myView.getId() == android.R.id.content)
46-
return myView.getTop();
47-
else
48-
return myView.getTop() + getRelativeTop((View)myView.getParent());
42+
Rect bounds = new Rect();
43+
myView.getGlobalVisibleRect(bounds);
44+
return bounds.top;
4945
}
5046

5147
public static int getRelativeLeft(View myView) {

MaterialDesign/src/com/gc/materialdesign/views/ButtonRectangle.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.gc.materialdesign.views;
22

3-
import com.gc.materialdesign.R;
4-
import com.gc.materialdesign.utils.Utils;
5-
63
import android.content.Context;
4+
import android.content.res.TypedArray;
75
import android.graphics.Canvas;
86
import android.graphics.Color;
97
import android.graphics.Rect;
@@ -12,6 +10,9 @@
1210
import android.widget.RelativeLayout;
1311
import android.widget.TextView;
1412

13+
import com.gc.materialdesign.R;
14+
import com.gc.materialdesign.utils.Utils;
15+
1516
/**
1617
* @tips :矩形按钮
1718
* @date :2014-11-1
@@ -95,6 +96,7 @@ else if(text != null ){
9596
params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()));
9697
textButton.setLayoutParams(params);
9798
addView(textButton);
99+
98100
}
99101

100102
@Override

MaterialDesign/src/com/gc/materialdesign/views/Slider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public interface OnValueChangedListener {
3030
public void onValueChanged(int value);
3131
}
3232

33-
Ball ball;
34-
NumberIndicator numberIndicator;
33+
private Ball ball;
34+
public NumberIndicator numberIndicator;
3535

3636
boolean showNumberIndicator = false;
3737
boolean press = false;
@@ -177,7 +177,7 @@ public boolean onTouchEvent(MotionEvent event) {
177177
// move number indicator
178178
numberIndicator.indicator.x = x;
179179
// 指示器起始的y坐标是当前控件的顶部Y坐标-当前控件高度的一半,就等于从空间的垂直中心开始。
180-
numberIndicator.indicator.finalY = Utils.getRelativeTop(this) - getHeight() / 2;
180+
numberIndicator.indicator.finalY = Utils.getRelativeTop(this) - getHeight() ;
181181
numberIndicator.indicator.finalSize = getHeight() / 2;
182182
numberIndicator.numberIndicator.setText("");
183183
}
@@ -332,7 +332,7 @@ public void changeBackground() {
332332

333333
// Slider Number Indicator
334334

335-
private class NumberIndicator extends Dialog {
335+
public class NumberIndicator extends Dialog {
336336

337337
private Indicator indicator;
338338
private TextView numberIndicator;

MaterialDesign/src/com/gc/materialdesign/widgets/ColorSelector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public interface OnColorSelectedListener{
121121

122122
@Override
123123
public void dismiss() {
124+
124125
Animation anim = AnimationUtils.loadAnimation(context, R.anim.dialog_main_hide_amination);
125126

126127
anim.setAnimationListener(new AnimationListener() {
208 Bytes
Binary file not shown.

MaterialDesignDemo/bin/classes.dex

372 Bytes
Binary file not shown.

MaterialDesignDemo/bin/resources.ap_

0 Bytes
Binary file not shown.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Some components have custom attributes, if you want use them, you must add this
105105
android:layout_marginRight="24dp"
106106
android:background="#1E88E5"
107107
materialdesign:animate="true"
108-
materialdesign:icon="@drawable/ic_action_new" />
108+
materialdesign:iconDrawable="@drawable/ic_action_new" />
109109
</RelativeLayout>
110110
```
111111

@@ -119,7 +119,7 @@ Some components have custom attributes, if you want use them, you must add this
119119
android:layout_width="wrap_content"
120120
android:layout_height="wrap_content"
121121
android:background="#1E88E5"
122-
materialdesign:icon="@drawable/ic_action_new" />
122+
materialdesign:iconDrawable="@drawable/ic_action_new" />
123123
```
124124

125125
####Switches

0 commit comments

Comments
 (0)