도트가 적용된 애니메이션 및 가로 효과가있는 시각적 효과가있는 사용자 정의 진행률 막대. 여기에이 코드를 게시하면 참조로 유지하면서 새로운 디자인을 이해하고 구현하는 데 도움이 될 수 있습니다. 희망이 당신을 도와줍니다.안드로이드에서 점진적 진행 표시 줄을 만드는 방법은 무엇입니까?
1
A
답변
11
MainActivity.java :
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rect"
android:gravity="center"
>
<com.example.horizontal.canvaslearn.HorizontalDottedProgress
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></com.example.horizontal.canvaslearn.HorizontalDottedProgress>
</LinearLayout>
HorizontalDottedProgress.java :,617,이것은 애니메이션이 적용된 도트를 만드는 맞춤 클래스입니다.
public class HorizontalDottedProgress extends View{
//actual dot radius
private int mDotRadius = 5;
//Bounced Dot Radius
private int mBounceDotRadius = 8;
//to get identified in which position dot has to bounce
private int mDotPosition;
//specify how many dots you need in a progressbar
private int mDotAmount = 10;
public HorizontalDottedProgress(Context context) {
super(context);
}
public HorizontalDottedProgress(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HorizontalDottedProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
//Method to draw your customized dot on the canvas
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
//set the color for the dot that you want to draw
paint.setColor(Color.parseColor("#fd583f"));
//function to create dot
createDot(canvas,paint);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
//Animation called when attaching to the window, i.e to your screen
startAnimation();
}
private void createDot(Canvas canvas, Paint paint) {
//here i have setted progress bar with 10 dots , so repeat and wnen i = mDotPosition then increase the radius of dot i.e mBounceDotRadius
for(int i = 0; i < mDotAmount; i++){
if(i == mDotPosition){
canvas.drawCircle(10+(i*20), mBounceDotRadius, mBounceDotRadius, paint);
}else {
canvas.drawCircle(10+(i*20), mBounceDotRadius, mDotRadius, paint);
}
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width;
int height;
//calculate the view width
int calculatedWidth = (20*9);
width = calculatedWidth;
height = (mBounceDotRadius*2);
//MUST CALL THIS
setMeasuredDimension(width, height);
}
private void startAnimation() {
BounceAnimation bounceAnimation = new BounceAnimation();
bounceAnimation.setDuration(100);
bounceAnimation.setRepeatCount(Animation.INFINITE);
bounceAnimation.setInterpolator(new LinearInterpolator());
bounceAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
mDotPosition++;
//when mDotPosition == mDotAmount , then start again applying animation from 0th positon , i.e mDotPosition = 0;
if (mDotPosition == mDotAmount) {
mDotPosition = 0;
}
Log.d("INFOMETHOD","----On Animation Repeat----");
}
});
startAnimation(bounceAnimation);
}
private class BounceAnimation extends Animation {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
//call invalidate to redraw your view againg.
invalidate();
}
}
}
스냅 촬영 :
내가 클래스 HorizontalDottedProgress을 사용했다
1
이 - 이것이 진정한 해결책이지만, 때로는 아주 작은 점을 그립니다. 또한이 위젯은 setVisibility (Visibility.GONE)에 반응하지 않으며 표시 후에 숨길 수 없습니다.
그래서이 클래스를 약간 수정 (자신의 이름이 바뀌 었습니다)했습니다. 도트 크기 및 거리는 화면 밀도를 사용하여 계산됩니다. 기능 onDraw()는 그리기 전에 isShown()을 검사합니다.
그런 다음 레이아웃에서 몇 가지 속성 (예 : 색상, 개수 및 시간 초과)을 지정할 가능성을 추가했습니다. 내 프로젝트에서 나는 다음과 같은 방법을 사용 : 자세한 내용은
<declare-styleable name="ToolDotProgress">
<attr name="color" format="color" />
<attr name="count" format="integer" />
<attr name="timeout" format="integer" />
</declare-styleable>
읽기 :
<my.domain.tools.ToolDotProgress
android:id="@+id/dots_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:color="@color/colorAccent"
app:count="5"
app:timeout="300" />
나는 입술/값/다음 코드 attrs.xml이 파일에 추가 한 다음 속성을 선언하려면 수동 : 여기 https://developer.android.com/training/custom-views/create-view.html
이 클래스의 내 변종 :
public class ToolDotProgress extends View {
// distance between neighbour dot centres
private int mDotStep = 20;
// actual dot radius
private int mDotRadius = 5;
// Bounced Dot Radius
private int mBigDotRadius = 8;
// to get identified in which position dot has to bounce
private int mDotPosition;
// specify how many dots you need in a progressbar
private static final int MIN_COUNT = 1;
private static final int DEF_COUNT = 10;
private static final int MAX_COUNT = 100;
private int mDotCount = DEF_COUNT;
private static final int MIN_TIMEOUT = 100;
private static final int DEF_TIMEOUT = 500;
private static final int MAX_TIMEOUT = 3000;
private int mTimeout = DEF_TIMEOUT;
private int mDotColor = Color.parseColor("#fd583f");
public ToolDotProgress(Context context) {
super(context);
initDotSize();
}
public ToolDotProgress(Context context, AttributeSet attrs) {
super(context, attrs);
initDotSize();
applyAttrs(context, attrs);
}
public ToolDotProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initDotSize();
applyAttrs(context, attrs);
}
private void initDotSize() {
final float scale = getResources().getDisplayMetrics().density;
mDotStep = (int)(mDotStep * scale);
mDotRadius = (int)(mDotRadius * scale);
mBigDotRadius = (int)(mBigDotRadius * scale);
}
private void applyAttrs(Context context, AttributeSet attrs) {
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.ToolDotProgress, 0, 0);
try {
mDotColor = a.getColor(R.styleable.ToolDotProgress_color, mDotColor);
mDotCount = a.getInteger(R.styleable.ToolDotProgress_count, mDotCount);
mDotCount = Math.min(Math.max(mDotCount, MIN_COUNT), MAX_COUNT);
mTimeout = a.getInteger(R.styleable.ToolDotProgress_timeout, mTimeout);
mTimeout = Math.min(Math.max(mTimeout, MIN_TIMEOUT), MAX_TIMEOUT);
} finally {
a.recycle();
}
}
//Method to draw your customized dot on the canvas
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isShown()) {
Paint paint = new Paint();
paint.setColor(mDotColor);
createDots(canvas, paint);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
startAnimation();
}
private void createDots(Canvas canvas, Paint paint) {
for (int i = 0; i < mDotCount; i++) {
int radius = (i == mDotPosition) ? mBigDotRadius : mDotRadius;
canvas.drawCircle(mDotStep/2 + (i * mDotStep), mBigDotRadius, radius, paint);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// MUST CALL THIS
setMeasuredDimension(mDotStep * mDotCount, mBigDotRadius * 2);
}
private void startAnimation() {
BounceAnimation bounceAnimation = new BounceAnimation();
bounceAnimation.setDuration(mTimeout);
bounceAnimation.setRepeatCount(Animation.INFINITE);
bounceAnimation.setInterpolator(new LinearInterpolator());
bounceAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
if (++mDotPosition >= mDotCount) {
mDotPosition = 0;
}
}
});
startAnimation(bounceAnimation);
}
private class BounceAnimation extends Animation {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
// call invalidate to redraw your view again
invalidate();
}
}
}
관련 문제
- 1. 섹션이있는 진행 표시 줄을 만드는 방법은 무엇입니까?
- 2. jquery로 진행률 표시 줄을 만드는 방법은 무엇입니까?
- 3. 안드로이드에서 listview show progressbar를 만드는 방법은 무엇입니까?
- 4. 상태 표시 줄 내부에 진행 표시 줄을 정렬하는 방법은 무엇입니까?
- 5. LibGDX에서 시간 표시 줄을 만드는 방법은 무엇입니까?
- 6. 상태 표시 줄을 반투명하게 만드는 방법은 무엇입니까?
- 7. 안드로이드에서 원호 모양의 진행 표시 줄을 만들 수 있습니까?
- 8. PageMethods의 진행 표시 줄을 표시/숨기는 방법?
- 9. nsDialogs를 사용하여 진행률 표시 줄을 만드는 방법은 무엇입니까?
- 10. UITableView 셀에서 진행률 표시 줄을 만드는 가장 좋은 방법은 무엇입니까?
- 11. 코코아에서 수직 진행 바를 만드는 방법은 무엇입니까?
- 12. SilverLight 진행 표시 줄을보기 좋게 만드는 방법은 무엇입니까?
- 13. 하나의 진행 표시 줄을 변경하면 모든 진행 표시 줄이 변경됩니다.
- 14. 녹아웃이보기를 렌더링하는 동안 진행 표시 줄을 표시합니다.
- 15. 안드로이드에서 실시간 업데이트로 등급 표시 막대를 만드는 방법은 무엇입니까?
- 16. VideoView 또는 MediaController에 대한 사용자 지정 단추/진행 표시 줄을 만드는 방법은 무엇입니까?
- 17. 어떻게 세련된 진행 표시 줄을 생성하고이 같은 세련된 진행 표시 줄을 만들려면 그것을
- 18. 안드로이드에서 스레드 안전 점진적 다운로드
- 19. MonoDroid의 WebView에서 진행 표시 줄을 표시하는 방법
- 20. WPF 진행 표시 줄을 사용하는 방법?
- 21. UITableViewCell에서 순환 진행 표시 줄을 사용하는 방법?
- 22. 오류 진행 표시 줄을 사용 : 최대가
- 23. 진행 표시 줄을 숨김 해제하고로드 문제
- 24. 진행 표시 줄을 종료하고 새로운 화면으로 이동
- 25. 부트 스트랩 진행 표시 줄을 애니메이션하는 것처럼
- 26. 작업 표시 줄을 만드는 방법
- 27. 안드로이드에서 정적 진행 표시 줄 만들기
- 28. 코디와 네이티브 안드로이드에서 진행 대화 상자를 표시
- 29. javaFx의 진행 표시 줄 및 진행 표시기를 구성하는 방법은 무엇입니까?
- 30. iPhone 진행률 표시 줄을 버튼처럼 클릭 할 수있게 만드는 방법?
안녕하세요 가시성 더 사라 없다 일하면서 도울 수 있습니다. –
왜냐하면 애니메이션은 여전히 다음과 같이 첫 번째 선명한 애니메이션을 실행하고 있기 때문입니다 : horizontalDotsProgressBar.clearAnimation(); horizontalDotsProgressBar.setVisibility (View.GONE); –