Android 中的屏幕方向,横向
我想知道当手机方向改变时如何修改视图。例如,当您“以正常方式”握住手机时,我的应用程序运行良好,但当您将其移至横向位置时,应用程序外观会变得丑陋: -如何确保壁纸不会与手机一起“转动”,这是我的布局代码: 文件名:list-event.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ListView android:id="@android:id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/fon2"></ListView>
</LinearLayout>
如您所见,这只是一个简单的列表,但我希望背景保持不变。 我为布局和布局土地放置了相同的内容,我只是放置了相同的文件list_event,但我认为我需要添加一些命令以使背景图像以不同的方式定向。 我希望你能理解我写的东西 提前致谢
I would like to know how to modify views when the phone orientation is changed. Like for example my app works fine when you hold the phone "the normal way" but when you moove it into the landscape position then the app appearance becomes ugly:
-how to make sure the wallpaper doesn't "turn" together with the phone, here is my layout code:
name of file: list-event.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ListView android:id="@android:id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/fon2"></ListView>
</LinearLayout>
As you can see it's just a simple list but I would like the background to stay the same.
I put the same content for layout and layout-land I just put this same file list_event but I think I need to add some comand for the background image to be oriented in diferent way.
I hope you understand what I wrote
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在横向和纵向模式下为视图创建不同的布局,并将横向布局放在
res/layout-land
中,将纵向布局放在res/layout-port
中(从技术上讲,您只需需要布局和布局 - {land,port},因为如果没有给出方向限定符,则布局是后备)。请参阅文档了解更多信息。
Create different layouts for your views in landscape and portrait mode and put the landscape ones in
res/layout-land
and the portrait ones inres/layout-port
(technically you only need layout and layout-{land,port} as layout is the fallback if no orientation qualifier is given).See the docs for more info.
在您的景观布局中(请参阅 Heiko 和 TofferJ 的答案),使用适合景观布局的另一张图像(具有所需的方向/尺寸)。
In your landscape layout (see Heiko's and TofferJ's answers), use another image, suited for the landscape layout (with the desired orientation/dimensions).
有关详细信息,请参阅此处的这篇文章:Android:横向模式的备用布局 xml
或者在这里查看 Google 的教程: http://developer.android.com /guide/topics/resources/providing-resources.html
See this post here för details: Android: alternate layout xml for landscape mode
Or check Google's tutorial here: http://developer.android.com/guide/topics/resources/providing-resources.html