安卓:从纵向转向横向到时按钮定位 [英] Android: Positioning buttons when turned from portrait to landscape

查看:116
本文介绍了安卓:从纵向转向横向到时按钮定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个菜单式的活动,其中我有几个定位的按钮。它非常适合我的手机屏幕上时,在纵向模式,但在横向模式下它的破坏。我知道,当我有固定的定位,这将是这个结果。谁能告诉我如何定位我的按钮,所以我的活动保持它的形式也以横向模式?谢谢你。

下面是我的XML文件:

 <?XML版本=1.0编码=UTF-8&GT?;
 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  的xmlns:工具=htt​​p://schemas.android.com/tool​​s
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  机器人:方向=垂直>
<按钮
     机器人:layout_width =WRAP_CONTENT
     机器人:layout_height =WRAP_CONTENT
     机器人:背景=@绘制/ bezpecnost_over
     机器人:layout_marginLeft =30dp
     机器人:layout_marginTop =50dp
      /><按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@绘制/ kurenie_over
    机器人:layout_marginLeft =200dp
    机器人:layout_marginTop =50dp     />  <按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@绘制/ osvetlenie_over
    机器人:layout_marginLeft =200dp
    机器人:layout_marginTop =200dp
    安卓的onClick =obrOsv/>
<按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT    机器人:背景=@绘制/ pohodlie_over
    机器人:layout_marginLeft =30dp
    机器人:layout_marginTop =200dp
    /> < / RelativeLayout的>


解决方案

  

它非常适合我的手机屏幕在纵向模式时,但在
  风景模式它的破坏。


这是预期的基于相对布局。通常做在这种情况下开发商是什么:


  • 请在水库被称为一个文件夹布局土地

  • 请与的相同的名称,在纵向模式布局的XML(包含在 RES /布局

  • 景观模式位置。

由于XML文件名是一样的,当它是时间设置内容查看活动

 的setContentView(R.layout.my_layout);

布局土地 my_layout.xml 文件文件夹将被用来代替。

另请阅读布局 &安培; 支持多种屏幕从Android文档,他们都与后者讲的是不同的限定词(如布局土地)。

有用的信息

I have a menu-activity, in which I have several positioned buttons. It fits my phone screen perfectly when in portrait mode, but in landscape mode it's destroyed. I know that when I have fixed positioning this will be the result. Can anyone tell me how to position my buttons so my activity keeps its form also in landscape mode? Thank you.

Here is my xml file:

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >


<Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/bezpecnost_over"
     android:layout_marginLeft="30dp"
     android:layout_marginTop="50dp"


      />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/kurenie_over"
    android:layout_marginLeft="200dp"
    android:layout_marginTop="50dp"

     />

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/osvetlenie_over"
    android:layout_marginLeft="200dp"
    android:layout_marginTop="200dp" 
    android:onClick="obrOsv"    />


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:background="@drawable/pohodlie_over"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="200dp"
    />

 </RelativeLayout>

解决方案

It fits my phone screen perfectly when in portrait mode, but in landscape mode it's destroyed.

This is expected for relative-based layouts. What developers usually do in this scenario:

  • Make a folder under res called layout-land
  • Make an xml with the same name as the layout in portrait mode (contained in res/layout)
  • Position for landscape mode.

Since the xml file name is the same, when it is time for the activity to set the content view

setContentView (R.layout.my_layout);

The my_layout.xml file from the layout-land folder will be used instead.

Also read Layouts & Supporting Multiple Screens from the Android docs, they both have useful information with the latter talking about the different qualifiers (such as layout-land).

这篇关于安卓:从纵向转向横向到时按钮定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆