Tôi cần tùy chỉnh thanh tìm kiếm theo cách mà, vào thời điểm xác định trước, 30 giây, tôi phải có dấu chấm trên thanh tìm kiếm. thời gian này thay đổi cho mỗi và mọi video, vì vậy làm thế nào để tôi đặt một dấu chấm điểm trên thanh tìm kiếm ở một đặc biệt thứ haitùy biến thanh tìm kiếm android,
5
A
Trả lời
16
Here're một số khả năng:
'chấm' xem- Đặt ngay trên
SeekBar
một. Sẽ không giải thích chi tiết ở đây, vì đó là nhiệm vụ bố trí android tầm thường; Mở rộng
SeekBar
, như sau (tham khảo this good explanation about custom views):/** * Seek bar with dots on it on specific time/percent */ public class DottedSeekBar extends SeekBar { /** Int values which corresponds to dots */ private int[] mDotsPositions = null; /** Drawable for dot */ private Bitmap mDotBitmap = null; public DottedSeekBar(final Context context) { super(context); init(null); } public DottedSeekBar(final Context context, final AttributeSet attrs) { super(context, attrs); init(attrs); } public DottedSeekBar(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); init(attrs); } /** * Initializes Seek bar extended attributes from xml * * @param attributeSet {@link AttributeSet} */ private void init(final AttributeSet attributeSet) { final TypedArray attrsArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.DottedSeekBar, 0, 0); final int dotsArrayResource = attrsArray.getResourceId(R.styleable.DottedSeekBar_dots_positions, 0); if (0 != dotsArrayResource) { mDotsPositions = getResources().getIntArray(dotsArrayResource); } final int dotDrawableId = attrsArray.getResourceId(R.styleable.DottedSeekBar_dots_drawable, 0); if (0 != dotDrawableId) { mDotBitmap = BitmapFactory.decodeResource(getResources(), dotDrawableId); } } /** * @param dots to be displayed on this SeekBar */ public void setDots(final int[] dots) { mDotsPositions = dots; invalidate(); } /** * @param dotsResource resource id to be used for dots drawing */ public void setDotsDrawable(final int dotsResource) { mDotBitmap = BitmapFactory.decodeResource(getResources(), dotsResource); invalidate(); } @Override protected synchronized void onDraw(final Canvas canvas) { super.onDraw(canvas); final int width = getMeasuredWidth(); final int step = width/getMax(); if (null != mDotsPositions && 0 != mDotsPositions.length && null != mDotBitmap) { // draw dots if we have ones for (int position : mDotsPositions) { canvas.drawBitmap(mDotBitmap, position * step, 0, null); } } } }
Đừng quên về attrs tùy chỉnh trong
res/values/attrs.xml
:<resources> <declare-styleable name="DottedSeekBar"> <attr name="dots_positions" format="reference"/> <attr name="dots_drawable" format="reference"/> </declare-styleable> </resources>
Và sử dụng đoạn mã sau:
setContentView(R.layout.main); final DottedSeekBar bar = (DottedSeekBar) findViewById(R.id.seekBar); bar.setDots(new int[] {25, 50, 75}); bar.setDotsDrawable(R.drawable.dot);
với bố cục main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res/com.example.TestApp" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.TestApp.DottedSeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/seekBar" /> </LinearLayout>
hoặc chỉ main.xml duy nhất:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res/com.example.TestApp" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.TestApp.DottedSeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/seekBar" custom:dots_positions="@array/dots" custom:dots_drawable="@drawable/dot" /> </LinearLayout>
Bạn có thể lấy hình ảnh sau:
Tham khảo this example cho thêm ý tưởng;
Về đặt dấu chấm trên 'thời gian' cụ thể: SeekBar
không phải là về thời gian, do đó, nó tùy thuộc vào bạn để cung cấp bất kỳ logic thời gian liên quan.
Các vấn đề liên quan
- 1. Thanh tìm kiếm của Android đặt kiểu tùy chỉnh bằng hình ảnh chín vá
- 2. Cách thêm tùy chọn tìm kiếm vào Android Spinner?
- 3. cách giới hạn thanh tìm kiếm
- 4. thanh tìm kiếm vô hiệu hóa android cho bộ điều khiển âm thanh
- 5. Thanh tìm kiếm tăng chiều cao
- 6. Danh sách tìm kiếm Android khi nhập
- 7. Tùy biến spinner của thanh tác vụ
- 8. jqGrid: cách ẩn một trường tìm kiếm cụ thể trong thanh công cụ tìm kiếm
- 9. Làm cách nào để di chuyển thanh tìm kiếm trên Android một cách trơn tru?
- 10. Tìm kiếm tùy chỉnh của Google với hộp và nút tìm kiếm tùy chỉnh?
- 11. Android - Actionbar Sherlock - Bộ lọc tìm kiếm
- 12. Android: ListView tìm kiếm Bộ lọc
- 13. Tùy chỉnh tìm kiếm - cách định vị đúng hình ảnh "ngón tay cái" tùy chỉnh?
- 14. Thanh tìm kiếm không gọi tìm kiếmBarTextDidBeginChỉnh sửa
- 15. Cách tạo thanh tiến trình tùy chỉnh trong Android?
- 16. Android: Tiện ích tìm kiếm ActionBarSherlock
- 17. Làm cách nào để làm cho thanh tìm kiếm/thanh trượt được phân đoạn như sau?
- 18. Tìm kiếm tùy chỉnh Alfresco Solr
- 19. Sự khác nhau giữa Thanh tìm kiếm so với thanh tìm kiếm và bộ điều khiển hiển thị tìm kiếm là gì?
- 20. Android Action Bar với Kiện Tìm Kiếm Xem
- 21. Thanh tiến trình tìm kiếm đẹp trong java
- 22. Thanh tiến trình tùy chỉnh trong Android?
- 23. Thanh tác vụ Android tùy chỉnh
- 24. Thanh tìm kiếm Android có điểm đánh dấu tại các điểm tiến trình rời rạc
- 25. Thanh tìm kiếm của Android cách chặn kéo/tắt nó trong thời gian ngắn
- 26. Sửa đổi tiện ích con thanh tìm kiếm Android để hoạt động theo chiều dọc
- 27. Thanh tìm kiếm dọc của Android như Google Play Music App
- 28. Cách thay đổi âm lượng thiết bị từ thanh tìm kiếm trong android
- 29. Chuyển biến cho Công cụ Tìm kiếm Tùy chỉnh của Google
- 30. tùy biến phần listview
Bạn đã cố tạo chế độ xem tùy chỉnh chưa? – sandrstar
@sandrstar chế độ xem tùy chỉnh cho thanh tìm kiếm? một thanh tìm kiếm mở rộng lớp học? Không có ý tưởng nhiều như làm thế nào để đặt các dấu chấm. Bất kỳ trợ giúp nào được đánh giá cao, cảm ơn – user2558496