AttributeSet attrs
참고 :
https://gun0912.tistory.com/38
https://stackoverflow.com/questions/5316686/what-is-attributeset-and-how-can-i-use-it
https://gogorchg.tistory.com/entry/Android-CustomView%EC%97%90-Attribute-%EB%A7%8C%EB%93%A4%EA%B8%B0
https://gun0912.tistory.com/38
https://stackoverflow.com/questions/5316686/what-is-attributeset-and-how-can-i-use-it
https://gogorchg.tistory.com/entry/Android-CustomView%EC%97%90-Attribute-%EB%A7%8C%EB%93%A4%EA%B8%B0
2020년 5월 30일 토요일
Activity 스택 어떻게 해야할까
참고: https://m.blog.naver.com/PostView.nhn?blogId=estern&logNo=220012629594&proxyReferer=https:%2F%2Fwww.google.com%2F
Parcel 어떻게 해야 하나
참고
https://milkissboy.tistory.com/34
https://stackoverflow.com/questions/7181526/how-can-i-make-my-custom-objects-parcelable
https://stackoverflow.com/questions/42436012/how-to-put-the-arraylist-into-bundle
https://milkissboy.tistory.com/34
https://stackoverflow.com/questions/7181526/how-can-i-make-my-custom-objects-parcelable
https://stackoverflow.com/questions/42436012/how-to-put-the-arraylist-into-bundle
2020년 5월 29일 금요일
android progress bar 원형으로 setProgress 설정
progress bar ?
어떠한 작업을 수행할 시 기다려야 하는 하나의 표시로서 나타낼 수 있고, 퍼센트지로 작업 완료시점을 알릴 수 있습니다.
저는 XML을 통해서가 아닌 자바코드를 사용해서 레이아웃에 추가해보도록 하겠습니다.
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ProgressBar pg = new ProgressBar(getApplicationContext(),null
,android.R.attr.progressBarStyleLarge);
ViewGroup layout = findViewById(R.id.linearLayout);
layout.addView(pg);
}
이렇게 선언 하시면 가장 기본적인 모션으로 돌아가는 것 같습니다.
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ProgressBar pg = new ProgressBar(getApplicationContext(),null ,android.R.attr.progressBarStyleLarge); pg.setMax(100); pg.setProgress(50); LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout); layout.addView(pg);}Max와 Progress 를 설정했지만 위 영상과 같이 열심히 돌아기만 합니다.
하지만 돌아가는 모션이 아닌 상황에 따라 달라지게 할 수 없을까요 ?
setProgress 설정과 똑같이 적용될 수 있도록 말이죠.
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
ProgressBar pg = new ProgressBar(getApplicationContext(),null
,android.R.attr.progressBarStyleHorizontal);
// pg.set ViewGroup layout = findViewById(R.id.linearLayout);
layout.addView(pg);}
Large -> Horizontal 로 변경했습니다.
이렇게 하면 setProgress 설정이 반영되어 채워지게 됩니다.
하지만!! 이렇게 하면 원형이 아닌 일직선으로 스타일이 변경이 됩니다
원으로 하고싶은데..;;
drawable 폴더에 이름의 자유롭게 xml 파일로 하나 만들어주세요
저는 progressbar_ring으로 만들었습니다.
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:innerRadiusRatio="2.5" android:thickness="5dp" android:useLevel="true"> <solid android:color ="@color/colorAccent"></solid> </shape>
shape = "ring" 과 함께
링 비율과 링을 이루는 두께를 설정합니다.
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ProgressBar pg = new ProgressBar(getApplicationContext(),null ,android.R.attr.progressBarStyleHorizontal); pg.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_ring,null)); pg.setProgress(100); pg.setProgress(50); LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout); layout.addView(pg);}
Drawable 폴더에 생성한 xml 파일을 설정해주세요. 그리고 이대로 실행하면 화면이 짤려 보일거에요.
그래서 Layout 설정을 했습니다
짤려보이신다면 아래와 같이 설정해주세요
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ProgressBar pg = new ProgressBar(getApplicationContext(),null ,android.R.attr.progressBarStyleHorizontal); pg.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_ring,null)); LinearLayout.LayoutParams params =new LinearLayout.LayoutParams(200,200); pg.setLayoutParams(params); pg.setProgress(100); pg.setProgress(50); LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout); layout.addView(pg);}
LinearLayout.LayoutParams(200,200);
200,200 은 폭과 넓이를 의미합니다
https://www.youtube.com/watch?v=hSfN_aYKkzo
2020년 5월 27일 수요일
php 이미지 전송
Transition<? super Bitmap>
무슨 뜻일까
Glide.with(context)
.asBitmap()
.load(drawURL)
.into(new CustomTarget<Bitmap>() {
@Override public void onResourceReady(Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
// Do something with the Drawable here. }
@Override public void onLoadCleared(@Nullable Drawable placeholder) {
// Remove the Drawable provided in onResourceReady from any Views and ensure // no references to it remain. }
});
2020년 5월 26일 화요일
Glide
Glide란?
- 이미지 로딩 라이브러리이다.
- API를 사용하여 쉽게 조작할 수 있다.
우선 build.gradle 안에
implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
Glide.with(this)
.load(url)
.into(imageView);
간단하게 사용하는 방법을 위에 있는 문장을 사용하여 괄호() 안에만 넣어주면 된다. 자동적으로 다운샘플링 되기 때문에 이미지 사이즈를 줄여서 저장하게 된다.
여기서 궁금한 점! 대부분의 글이나 이미지를 불러온다면 open 을 명시해주고 close로 닫아준다. 과연 우리의 Glide는 어떤 방법을 써야할까 .
Glide.with(fragment).clear(imageView);
이렇게 사용해야겠지만
this에 대한 Activity가 destroy 될 때 , 자동으로 clear 된다.이 밑에 부터는 제가 필요한 것만 정리해 놓았습니다.Background Threads
FutureTarget<Bitmap> futureTarget = Glide.with(context) .asBitmap() .load(url) .submit(width, height); Bitmap bitmap = futureTarget.get(); // Do something with the Bitmap and then when you're done with it: Glide.with(context).clear(futureTarget);
에러처리를 요청으로
Glide.with(fragment) .load(primaryUrl) .error( Glide.with(fragment) .load(fallbackUrl)) .into(imageView);
Option 적용
RequestOptions options = new RequestOptions() .set(MyCustomModelLoader.TIMEOUT_MS, 1000L); Glide.with(context) .load(url) .apply(options) .into(imageView);
참고:
https://bumptech.github.io/glide/
android 진짜 화면 사이즈를 알아보자
https://myksb1223.github.io/develop_diary/2019/03/28/Screen-size-in-Android.html
https://stackoverflow.com/questions/3591784/views-getwidth-and-getheight-returns-0
2020년 5월 15일 금요일
쓰레드 오류와 해결 접근
쓰레드 오류가 났다
어렴풋이 알고 있었지만 오늘은 개념을 잡아보려고 한다.
우선 간단히 쓰레드란 ?
위키백과에 나온 정의는 ..
handler는 UI 변경 시 sendMessage로 메세지 큐에 넣는다
필요 시 루퍼가 차례로 메세지를 꺼내 handlerMessage 메인쓰레드에게 넘겨주는 RUN()을 실행한다.
참고
https://devfarming.tistory.com/3
https://brunch.co.kr/@mystoryg/84
http://blog.naver.com/PostView.nhn?blogId=ssarang8649&logNo=220947884163
https://developer.android.com/reference/android/os/Handler#postAtTime(java.lang.Runnable,%20long)
어렴풋이 알고 있었지만 오늘은 개념을 잡아보려고 한다.
우선 간단히 쓰레드란 ?
위키백과에 나온 정의는 ..
프로세스 내에서 실행되는 흐름의 단위를 말한다. 일반적으로 한 프로그램은 하나의 스레드를 가지고 있지만, 프로그램 환경에 따라 둘 이상의 스레드를 동시에 실행할 수 있다. 이러한 실행 방식을 멀티스레드(multithread)라고 한다.안드로이드에서는 MainThread에서 UI를 처리한다. 그렇기에 따른 쓰레드에서 UI를 실행하는 일은 없도록 해야한다. 내가 배웠던 방식중에 하나는 asynctask가 있었다. 이 이야기는 간략하게나마 포스팅을 했고 , 최근에는 Handler라는 방식을 알게 되었다.
handler는 UI 변경 시 sendMessage로 메세지 큐에 넣는다
필요 시 루퍼가 차례로 메세지를 꺼내 handlerMessage 메인쓰레드에게 넘겨주는 RUN()을 실행한다.
참고
https://devfarming.tistory.com/3
https://brunch.co.kr/@mystoryg/84
http://blog.naver.com/PostView.nhn?blogId=ssarang8649&logNo=220947884163
https://developer.android.com/reference/android/os/Handler#postAtTime(java.lang.Runnable,%20long)
2020년 5월 5일 화요일
Observer and Observable 차이
Observer
Observable
참고 : https://www.javaworld.com/article/2077258/observer-and-observable.html
- interface
Observable
- class
참고 : https://www.javaworld.com/article/2077258/observer-and-observable.html
피드 구독하기:
글 (Atom)