android Spinner: văn bản trung tâm theo chiều dọc bên trong spinner
tôi cần các trình xoay vòng này để căn giữa văn bản. Tôi đã thử các công cụ như thế này trong định nghĩa xml Spinner:
<Spinner
android:id="@+id/dir_spn"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_weight="1"/>
tôi đã cố gắng xây dựng một phong tục thả xuống bố trí:
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/SpinnerDropDownItem"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />
styles.xml:
<resources>
<style name="SpinnerDropDownItem">
<item name="android:gravity">center_vertical</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textColorHighlight">#FFFF9200</item>
<item name="android:textColorHint">?android:attr/textColorHint</item>
<item name="android:textColorLink">#5C5CFF</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
</style>
</resources>
bộ chuyển đổi thả xuống bộ :
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
ho w để tôi có được văn bản Spinner đến trung tâm theo chiều dọc?
EDIT: nó có thể là đáng nói đến là Hoạt động được theo chủ đề trong biểu hiện thusly:
<resources>
<style name="SpeakNSpell" parent="@android:style/Theme">
<item name="android:minHeight">68sp</item>
</style>
</resources>
mà làm cho tất cả các lần xem ít nhất 68sp cao. điều này có ảnh hưởng đến văn bản bên trong Spinner không?
Tôi sẽ làm giảm nó vào dạng đơn giản và đi từ đó. Đầu tiên hãy thử nó mà không có phong cách và widget ưa thích. Tạo bố cục TextView đơn giản và đặt trọng tâm thành center_vertical và xem liệu nó có hoạt động hay không. Ngoài ra, bố trí thả xuống là * không * hiển thị khi trình xoay được đóng (khi bạn đang hiển thị nó). Có lẽ bạn cần phải áp dụng phong cách của bạn để bố trí được sử dụng khi spinner được đóng lại? – Barak
Tôi không thấy máy quay của bạn 'android: layout_width =" wrap_content "' và 'android: layout_height =" wrap_content "' – slybloty