마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

seekbar가 안보입니다.

0 추천

분명히 디자인 화면에서는 보이는데 실제 디바이스에서 실행시켜보면 보이질 않네요..

thumb만 보이고 seekbar는 안보이는 이상한 현상이 나타납니다.. 근데 이유를 모르겠네요..

<MainActivity>

public class MainActivity extends AppCompatActivity {
    MediaPlayer mp;
    int pos;
    private Button bStart;
    SeekBar sb;
    boolean isPlaying = false;

    class MyThread extends Thread {
        @Override
        public void run(){
            while(isPlaying){
                sb.setProgress(mp.getCurrentPosition());
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        sb = (SeekBar) findViewById(R.id.seekBar1);
        sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if(seekBar.getMax() == progress){
                    bStart.setVisibility(View.VISIBLE);
                    isPlaying = false;
                    mp.stop();
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                isPlaying = false;
                mp.pause();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                isPlaying = true;
                int ttt = seekBar.getProgress();
                mp.seekTo(ttt);
                mp.start();
                new MyThread().start();
            }
        });

        bStart = (Button) findViewById(R.id.button1);

        bStart.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                mp = MediaPlayer.create(getApplicationContext(), R.raw.flower);
                mp.setLooping(false);
                mp.start();

                int a = mp.getDuration();
                sb.setMax(a);
                new MyThread().start();
                isPlaying = true;

                bStart.setVisibility(View.INVISIBLE);
            }
        });
    }

    @Override
    protected void onPause(){
        super.onPause();
        isPlaying = false;
        if(mp != null){
            mp.release();
        }
        bStart.setVisibility(View.VISIBLE);
    }
}

 

<activity_main>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/activity_main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="speakeragent.com.testagentplayer.MainActivity">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="MediaPlayer 활용"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:text="시작" />

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="18dp"
        android:progressDrawable="@drawable/seekbar_seekbar1"
        android:thumb="@drawable/seekbar_thumb1"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:thumbOffset="0dp"
        />
</RelativeLayout>

 

<seekbar_seekbar1>

<?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 android:shape="line">
            <stroke android:width="6dp" android:color="#D5D5D5" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape android:shape="line">
                <stroke android:width="6dp" android:color="#B2CCFF"/>
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="line">
                <stroke android:width="6dp" android:color="#6799FF"/>
            </shape>
        </clip>
    </item>
</layer-list>

 

<seekbar_thumb1>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#B2CCFF"></solid>
    <stroke android:width="2dp"
        android:color="#B2CCFF"/>
    <size
        android:width="6dp"
        android:height="6dp"/>
</shape>

 

한 가지 이상한점은 activity_main파일에서 아래의 코드를 없애면 seekbar가 보입니다.

android:thumb="@drawable/seekbar_thumb1"

문제가 뭔지.. 잘 모르겠네요.. 

 

익명사용자 님이 2017년 5월 23일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...