'Android'에 해당하는 글 4건

반응형

 

byte[]에서 Bitmap으로 변환후 가로길이가 세로길이보다 클 경우 Bitmap 이미지를 회전시킨다.

Bitmap bitmap = byteArrayToBitmap(data);
if (bitmap.getHeight() < bitmap.getWidth()){
bitmap = imgRotate(bitmap, 90);
}
imgView.setImageBitmap(bitmap);
 
 
//byte[] bitmap으로 변환
private Bitmap byteArrayToBitmap(byte[] byteArray){
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
return bitmap;
}

//bitmap이미지를 원하는각으로 회전
private Bitmap imgRotate(Bitmap bitmap, int angle){
int width = bitmap.getWidth();
int height = bitmap.getHeight();

Matrix matrix = new Matrix();
matrix.postRotate(angle);

Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
bitmap.recycle();

return resizedBitmap;
}
 
반응형

WRITTEN BY
아카이시

,
반응형

Examining the ViewPager #3

This article is part of a series of articles about the ViewPager component. Click here to see a list of all articles of this series.

Horizontal scrolling pages

Have you ever tried putting horizontal scrolling components inside a ViewPager? Well, since revision 9 of the support library this is supported by the ViewPager. As long as the inner component can scroll horizontally this component will be scrolled. Whenever the component can't be further scrolled the ViewPager will handle the touch events and you start to switch to the next page. This works out-of-the-box for scrolling view components of Android like the WebView.

Internally the ViewPager uses ViewCompat.canScrollHorizontally(View v, int direction) to determine if a child view can be scrolled horizontally and should receive the according touch events. Unfortunately this method is only implemented for Android 4.0 (API level 14) and above. For all earlier versions this method will always return false and therefore never scroll the components inside the ViewPager.

 

Fake dragging

The ViewPager supports fake dragging. Fake dragging can be used to simulate a dragging event/animation, e.g. for detecting drag events on a different component and delegating these to the ViewPager.

You have to signal the ViewPager when to start or end a fake drag by calling beginFakeDrag() and endFakeDrag() on it. After starting a fake drag you can use fakeDragBy(float) to drag the ViewPager by the given amount of pixels along the x axis (negative values to the left and positive values to the right).

The following example uses a SeekBar whose current progress state is used to fake drag a ViewPager by the given percentage.



 

 

 

 

 

 

반응형

'안드로이드 개발' 카테고리의 다른 글

정적 변수와 메소드 (static)  (0) 2015.05.28
안드로이드 폰 정보  (0) 2015.05.27
안드로이드 OS버젼체크  (0) 2015.05.08
android layoutparams사용시 주의할점  (0) 2015.05.08
synchronized 란...  (0) 2015.05.08

WRITTEN BY
아카이시

,
반응형

xml파일에서 정의하지 않거나 동적으로 자바 파일에서 레이아웃의 사이즈, 마진등을 조정해야 할경우 LayoutParams를 사용한다.

ViewGroup.LayoutParams,

ViewGroup.MarginLayoutParams,

LinearLayout.LayoutParams,

AbsoluteLayout.LayoutParams,

RelativeLayout.LayoutParams

setLayoutParams을 쓸 경우 주의할점이 있다.

setLayoutParams을 사용하고자하는 레이아웃의 부모뷰의 LayoutParams를 생성하여야 한다.

예)

<LinearLayout>

<TableLayout>....</TableLayout>

</LinearLayout>

일 경우

TableLayout homeMenu = (TableLayout)view.findViewById(R.id.home_menu);

LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(menuWidth, menuHeight);
homeMenu.setLayoutParams(param);

반응형

'안드로이드 개발' 카테고리의 다른 글

안드로이드 폰 정보  (0) 2015.05.27
Fake dragging  (0) 2015.05.22
안드로이드 OS버젼체크  (0) 2015.05.08
synchronized 란...  (0) 2015.05.08
안드로이드 화면사이즈 구하기  (0) 2015.05.07

WRITTEN BY
아카이시

,
반응형
synchronized 란...

하나의 자원(데이터)에 대하여 여러 스레드가 사용되려고 할때 한 시점에서 하나의 스레드만 사용할수 있도록 하는것이다. synchronized 식별자는 보통 메소드의 선언부에 쓰고 이 키워드가 붙은 메소드는 한번에 하나의 스레드만 접근이 가능하며 메소드가 사용중일 때  다른 스레드가 메소드를 호출하면 앞의 스레드가 종료될때까지 기다려야 한다.

synchronized는 하나의 객체에 여러개의 객체가 동시에 접근해 처리하는것으 막기위해 사용한다. 메소드를 동기화 하려면 메소드 선언분에 synchronized 식별자를 쓰고, 특정부분을 동기화하려면 해당 코드 블록에 선언해서 사용하면 된다.애플리케이션 성능에 있어 이 식별자의 영향력이 막강함에 비해 사용법은 간단하다.

예)

public synchronized static DBMovies getWritableDatabase() {
        if (mDatabase == null) {
            mDatabase = new DBMovies(getAppContext());
        }
        return mDatabase;
    }

 

반응형

'안드로이드 개발' 카테고리의 다른 글

안드로이드 폰 정보  (0) 2015.05.27
Fake dragging  (0) 2015.05.22
안드로이드 OS버젼체크  (0) 2015.05.08
android layoutparams사용시 주의할점  (0) 2015.05.08
안드로이드 화면사이즈 구하기  (0) 2015.05.07

WRITTEN BY
아카이시

,