Forcing the Issue
In the previous three sections, we covered ways to deal with rotational events. There is, of course, a radical alternative: tell Android not to rotate your activity at all. If the activity does not rotate, you do not have to worry about writing code to deal with rotations.
To block Android from rotating your activity, all you need to do is add (or , as you prefer) to your file, as shown (from the sample project):
Since this is applied on a per‑activity basis, you will need to decide which of your activities may need this turned on.
At this point, your activity is locked into whatever orientation you specified, regardless of what you do. The following screen shots show the same activity as in the previous three sections, but using the previous manifest and with the emulator set for both portrait and landscape orientation. Note that the UI does not move a bit, but remains in portrait mode as can be seen in Figures 26‑3 and 26‑4.
Figure 26‑3. The RotationFour application, in portrait mode
Figure 26‑4. The RotationFour application, in landscape mode
Дата добавления: 2015-05-16; просмотров: 869;