woong's

Android Custom SeekBar 사용하기 본문

Develop/Android

Android Custom SeekBar 사용하기

dlsdnd345 2016. 2. 14. 17:11
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Android Custom SeekBar 사용하기


안녕하세요. 오랜만에 포스팅을 작성하는 것 같습니다.


매번 SeekBar 를 디자인 입히는 경우에 고생을 하는거 같아 이렇게 포스트를 작성 하고 있습니다 .


SeekBar 의 디자인을 입히는경우는 굉장히 쉽습니다 .

하지만 디자인을 입히고 사이즈를 바꿀경우 Thumb 가 중앙에 맞지 않는경우와 


Seekbar 터치시 터치가 잘 되지 않는 경우가 있었습니다 .


Colored By Color Scripter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 
    <!-- 배경 -->
    <item android:id="@android:id/background">
        <shape>
            <gradient
                android:centerColor="#A5A5AE"
                android:endColor="#A5A5AE"
                android:startColor="#A5A5AE" />
        </shape>
    </item>
    <!-- 프로그래스바 색상 -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:angle="0"
                    android:centerColor="#569EFF"
                    android:endColor="#569EFF"
                    android:startColor="#569EFF" />
            </shape>
        </clip>
    </item>
 
</layer-list>

 

 

​저는 색상을 통해서 시크바를 디자인 해보았습니다 . 


이렇게 진행하고 시크바 높이를 줄이니 Thumb 가 중앙에 안맞는 버그가 발생 했습니다 .


1
2
3
4
5
6
7
8
9
10
                <SeekBar
                    android:id="@+id/seekBar_music"
                    android:layout_width="240dp"
                    android:layout_height="wrap_content"
                    android:maxHeight="5dp"
                    android:minHeight="5dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:progressDrawable="@drawable/seek_bar_effecter"
                     />

 

 

​그래서 높이를 처음에는 고정값으로 지정하였으나 , wrap_content 로 변경후  

min , max height 를 고정값으로 변경하니 중앙에 위치 할 수 있었습니다 .


또한 현재는 Thumb 이미지가 있어서 Thumb 를 없애기 위해서 null 처리를 진행하였으나 ,

null 처리를 하면 터치가 잘안되는 현상이 있었습니다 .


그래서 null 처리 대신 알파값 처리를 진행 했습니다 .


1
seekBarMusic.getThumb().mutate().setAlpha(0);

 

 

​자바 코드를 통해서 알파값을 지정해 주니 터치가 잘되는 시크바가 되었습니다 . 



Comments