【发布时间】:2012-07-27 10:37:33
【问题描述】:
我想在操作栏中放置一个微调器,就像在 Gmail 应用中一样。所以我创建了以下布局。
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/spinner_list_item_selected_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:gravity="center"
android:text="Sales" />
<TextView android:id="@+id/spinner_list_item_selected_text" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:gravity="center"
android:text="" />
</LinearLayout>
然后使用以下代码将此微调器加载到标题栏:
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getActionBar().setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);
它按预期工作,除了在横向模式下,文本不适合。在 Gmail 应用程序中,字体大小会减小。 有没有办法根据方向自动调整字体大小?
【问题讨论】:
-
根据您的问题,您知道如何包装 selected 元素内容(我的意思是文本)吗?我试图重现 Actionbar Gmaps 和 Gmail 微调器样式,但我不能。我的微调器宽度似乎被“下拉项目”内容拉长。如果 drop 中的项目有一个太大的元素,那么微调器会被拉伸。有没有办法包装微调器选定的元素?