2

In iOS there is a notion of UIView's being able to resize themselves based on constraints given by the parent View. For example, if the parent View enlarges itself, then the child Views might expand or shrink to fit the available space. This is built in to the platform and makes development trivial.

So, my problem is that I am developing a smartphone application that makes use of the ActionBar in ICS. I have a custom view in there that I set using:

actionBar.setCustomView(R.layout.my_custom_title);

Note that I'm just inflating a view from the 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>

Now, in ICS, the ActionBar changes its height during an orientation change. It is narrower in landscape mode than in portrait mode. This causes my "subtitle" text to be cut off in landscape mode since the height of the ActionBar has shrunk, while my custom title view text has not resized itself.

Is it possible to resize the text on orientation change without programmatically doing so?

I'm overring

onConfigurationChanged()

so I can't just have a separate landscape and portrait custom title view.

SIDE NOTE: This reminds me... I wish in the onConfigurationChanged() we can just supply a new xml layout that basically just adjusts the positioning of the views on the screen. The portrait and xml layouts would have to contain the same views of course, but there would be different layout information. This would make life much easier and would be more efficient than having onCreate() called again.

mdupls
  • 2,012
  • 1
  • 27
  • 40

1 Answers1

2

Your TextView has changed its size but the text size has not changed. There is no way to change the text size without some extra effort but you have different options:

  1. you define different text size values for portrait and landscape mode and dont override onConfigurationChanged. This can by done by creating two dimensions.xml. One is inside res/values-land and the other in res/values-port
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="font_size">16dp</dimen>
</resources>

And in your layout assign that value to your TextView

<TextView 
    android:textSize="@dimen/font_size"
  1. Second option is to compute the font size programatically. This was already covered in another question
Community
  • 1
  • 1
Renard
  • 6,909
  • 2
  • 27
  • 23