Tôi đang phát triển một ứng dụng cho ngôn ngữ RTL và muốn thay đổi vị trí của mũi tên ở bên trái của Spinner! Có cách nào để thực hiện việc này mà không cần tạo trình xoay tùy chỉnh không?Spinner với mũi tên ở bên trái
9
A
Trả lời
8
Bạn phải viết spinner tùy chỉnh. Mã mẫu dưới đây. Bạn có thể chỉnh sửa theo ý muốn.
<Spinner
style="@style/spinner_style"
android:layout_width="match_parent"
android:layout_height="wrap content"
/>
@ style/spinner_style:
<style name="spinner_style">
<item name="android:background">@drawable/background_spinner</item>
</style>
@ drawable/background_spinner
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><layer-list>
<item><shape>
<solid android:color="@android:color/white" />
<corners android:radius="4dp" />
<padding android:left="8dp"/>
</shape></item>
<item><bitmap android:gravity="left"
android:src="@drawable/ic_arrow_drop_down_grey600_36dp"/>
</item>
</layer-list></item>
</selector>
3
Một cách dễ dàng và đơn giản để thiết mũi tên ở phía bên trái được, Bạn phải tạo file .xml trong thư mục có thể kéo cho điều đó như được viết bên dưới:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorWhite" />
</shape>
</item>
<item
android:drawable="@drawable/ic_arrow_drop_down_black_24dp"
android:right="320dp"/>
</layer-list>
Bạn có thể điều chỉnh mã ở trên theo nhu cầu của mình. Và thiết lập tập tin này là nền tảng của một widget spinner như sau:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout_spinner"
android:background="@drawable/arrow_left"
android:elevation="5dp"/>
1
dummy.xml (drawable nên có kích thước-24dp rất thấp)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list android:opacity="transparent">
<item android:width="100dp" android:end="300dp">
<bitmap android:src="@drawable/down_button_dummy_dummy" android:gravity="center"/>
</item>
</layer-list>
</item>
</selector>
đoạn file layout
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
app:cardElevation="5dp"
>
<Spinner
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/dummy">
</Spinner>
</android.support.v7.widget.CardView>
Các vấn đề liên quan
- 1. Android - Xóa mũi tên thả xuống Spinner
- 2. Tạo một tùy chỉnh trái lại nút trên UINavigationBar VỚI vào mũi tên tiêu chuẩn trên bên trái
- 3. Mũi tên thả xuống Spinner của Android không hiển thị
- 4. Nhấn vào mũi tên tiếp tục bên trái trong các biểu tượng emacs trên Windows 7
- 5. HorizontalScrollView với các mũi tên
- 6. MSysGit Bash - cách bật Ctrl + Mũi tên Trái/Phải?
- 7. Owl Carousel Mũi tên bên ngoài Navigation
- 8. nghĩa mũi tên bên phải trong Scala
- 9. Mũi tên Haskell bên trong Tuples
- 10. đỏ biểu tượng mũi tên ở subclipse
- 11. Phụ kiện iOS UITableViewCell ở bên trái?
- 12. Điều hướng danh sách thanh hành động + điều hướng tab - Vị trí của spinner không nằm ở bên trái nhất
- 13. Đường viền dày ở bên phải và bên trái
- 14. Tab ở bên phải và bên trái của TabControl C#
- 15. CSS giữ các phần tử ở trên cùng bên trái và bên trái
- 16. Swing: popover với mũi tên
- 17. mũi tên tròn với CSS
- 18. Vẽ mũi tên với XAML
- 19. Tính hữu ích của "mũi tên chức năng liên kết với bên phải"?
- 20. Mũi tên trong Hộp thoại jQuery
- 21. Navigate to rel = tiếp theo và rel = trước trang sử dụng trái và bên phải mũi tên
- 22. Bootstrap 3 Menu Navbar Collapse ở bên trái cho các thanh điều hướng bên trái và bên phải
- 23. Mũi tên tương đương với mapM?
- 24. Thêm mũi tên bên dưới trục x trong ô R
- 25. Gọi một IO Monad bên trong một mũi tên
- 26. Mũi tên ở dưới cùng của Hộp thoại jQuery
- 27. Đặt canvas gốc ở góc dưới bên trái
- 28. JTabbedPane: biểu tượng ở phía bên trái của các tab
- 29. IntelliJ - Hiển thị lỗi/cảnh báo ở bên trái mã
- 30. không thể tìm thấy một mũi tên bên phải unicode
Thêm người quen và giải thích lý do downVote? –