Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

android - How make seekbar like thermometer

I have customized the seek bar and its working fine, but the real problem is to draw the notched like thermometer on it which can be dynamic and takes the equal distance of that of the Seek Bar.

Example Seek Bar Max = 10 then there should be 10 segments, for which we need to draw 11 lines in equal distance so that the thumb comes exactly center to the notch.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To keep things simple you could use a seekbar with a RelativeLayout displaying a thermometer image in background.

Make sure you have a thermometer image in you drawbles folder. Just rotate your seekbar using android:rotation="-90"

         <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/root_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <RelativeLayout
                android:layout_width="632px"
                android:layout_height="1300px"
                android:layout_below="@+id/rel"
                android:layout_gravity="center"
                android:background="@drawable/thermometer1">

            </RelativeLayout>

            <SeekBar
                android:layout_width="1052px"
                android:layout_height="50dp"
                android:layout_marginLeft="136dp"
                android:layout_marginRight="12dp"
                android:layout_marginTop="338dp"
                android:rotation="-90"
                />

        </FrameLayout>

This is the result:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...