在 iOS 中,有一个 UIView 能够根据父 View 给出的约束来调整自身大小的概念。例如,如果父 View 自己放大,那么子 View 可能会扩大或缩小以适应可用空间。这是内置在平台中的,使开发变得微不足道。
所以,我的问题是我正在开发一个使用 ICS 中的 ActionBar 的智能手机应用程序。我在那里有一个自定义视图,我使用以下方法设置:
actionBar.setCustomView(R.layout.my_custom_title);
请注意,我只是从 xml 中扩充视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
style="@style/TextAppearance.Title.Theme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Title" />
<TextView
android:id="@+id/subtitle"
style="@style/TextAppearance.SubTitle.Theme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Subtitle" />
</LinearLayout>
现在,在 ICS 中,ActionBar 在方向更改期间会更改其高度。横向模式比纵向模式更窄。这导致我的“字幕”文本在横向模式下被截断,因为 ActionBar 的高度已经缩小,而我的自定义标题视图文本本身没有调整大小。
是否可以在不以编程方式更改方向的情况下调整文本大小?
我过头了
onConfigurationChanged()
所以我不能只拥有一个单独的横向和纵向自定义标题视图。
旁注:这提醒了我......我希望在 onConfigurationChanged() 中我们可以提供一个新的 xml 布局,基本上只是调整屏幕上视图的位置。纵向和 xml 布局当然必须包含相同的视图,但是会有不同的布局信息。这将使生活更轻松,并且比再次调用 onCreate() 更有效。