alex alex - 3 months ago 22
Android Question

Android create seekbar

i have this layout :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="---------"
android:background="@color/cast_expanded_controller_background_color">


<VideoView
android:id="@+id/videoItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:src="@drawable/sfondo_alto"
android:scaleType="centerCrop"
android:id="@+id/imageView2" />

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/back"
android:id="@+id/backBtn"
android:padding="10dp"/>
<TextView
android:id="@+id/titolo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView2"
android:layout_toRightOf="@+id/backBtn"
android:layout_toEndOf="@+id/backBtn"
android:layout_alignParentTop="true"
android:text="Un due tre prova un due"
android:textColor="@color/cast_expanded_controller_text_color"
android:gravity="center_vertical"
android:fontFamily="fonts/Quicksand_Bold"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/sfondo_alto"
android:scaleType="centerCrop"
android:id="@+id/imageView6" />


<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="13dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/icona_pausa"
android:id="@+id/play_pausa" />


<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="13dp"
android:src="@drawable/ridimensiona_grande"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/ridimensionaImage" />

<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginBottom="22.5dp"
android:layout_marginRight="55dp"
android:layout_marginLeft="5dp"
android:src="@drawable/ret_bianco"
android:scaleType="centerCrop"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/ridimensionaImage"
android:layout_toRightOf="@+id/play_pausa"
android:layout_toEndOf="@+id/play_pausa" />


</RelativeLayout>


and the result is this :
enter image description here

How can i create a ImageView(seekpoint) that moves on the seekbar?
i also need a way to press the seekBar in a point and receive a percentage of the tap position

this is a remote video player
Sorry for bad english, i'm italian(:

Answer

Add this in your xml layout

             <SeekBar
                    android:id="@+id/seekBar_days"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="20dp"
                    android:layout_weight=".7"
                    android:max="31"
                    android:maxHeight="3dp"
                    android:progressDrawable="@drawable/seekbar_progress"
                    android:thumb="@drawable/thum" />

creat a drawable resource seekbar_progress.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <corners android:radius="5dip" />
        <gradient
            android:startColor="#ff9d9e9d"
            android:centerColor="#ff5a5d5a"
            android:centerY="0.75"
            android:endColor="#ff747674"
            android:angle="270"
            />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                android:startColor="#80ffd300"
                android:centerColor="#80ffb600"
                android:centerY="0.75"
                android:endColor="#a0ffcb00"
                android:angle="270"
                />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="@color/primary"
                android:angle="270"
                />
        </shape>
    </clip>
</item>

use this image for seekbar point

enter image description here

Comments