본문 바로가기
MOBILE/Android

20180802 오늘자 안드로이드 정리

by 지구 2018. 8. 2.

1. Glide 사용법

1
2
3
ImageView splashView = (ImageView)findViewById(R.id.splashView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(splashView);
Glide.with(this).load(R.raw.splash_main).into(imageViewTarget);
cs


2. 기본, 깔끔한 splash 만드는 방법에 대해 잘 알려주는 기본 예제

사이트 : https://lx5475.github.io/2017/07/15/android-splash/


3. ButtomNavigation 과 Fragment 를 섞은 단순한, 알기 쉬운 좋은 예제

사이트 : https://github.com/Truiton/BottomNavigation


4. findViewById 는 Activity 에서만 된다, Flagment 에서는 getView(). 으로 사용하면 된다.

출처 : https://hashcode.co.kr/questions/125/fragment%EC%97%90%EC%84%9C-findviewbyid%ED%95%98%EB%8A%94%EB%B2%95

ImageView imageView = (ImageView) getView().findViewById(R.id.foo);


5. A flagment 에서 B flagment 로 이동할 때 ( Intent 처럼 하고 싶을 때 )

프레그먼트에서는 this 를 사용하지 못하기 때문에 getActivity() 로 처리하면 된다.

1
2
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
cs


6. ImageView 에 URL 로 이미지 가져와서 뿌려주기

URL 로 작업하는 부분이라 별도의 스레드를 생성해서 돌려야 함

출처 : http://apphappy.tistory.com/131

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//프로필사진을 외부에서 받아 ImageView에 씌우는 메소드
    private void LoadUserProfile(){
        Thread imgThread = new Thread(){
            @Override
            public void run(){
                try {
                    URL url = new URL(imgPath);
                    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
                    conn.setDoInput(true);
                    conn.connect();
                    InputStream is = conn.getInputStream();
                    bitmap = BitmapFactory.decodeStream(is);
                }catch (IOException e){
                }
            }
        };
        imgThread.start();
        try{
            imgThread.join();
            userProfileImg.setImageBitmap(bitmap);
        }catch (InterruptedException e){
        }
    }
cs


반응형

댓글