2

いくつかの配置されたボタンがあるメニューアクティビティがあります。縦向きモードでは携帯電話の画面に完全にフィットしますが、横向きモードでは壊れます。ポジショニングを固定すると、これが結果になることはわかっています。私のアクティビティが横向きモードでもフォームを維持できるように、ボタンを配置する方法を誰か教えてもらえますか? ありがとうございました。

ここに私のxmlファイルがあります:

  <?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>
4

2 に答える 2

3

縦向きモードでは携帯電話の画面に完全にフィットしますが、横向きモードでは壊れます。

これは、相対ベースのレイアウトで予想されます。このシナリオで開発者が通常行うこと:

  • res という名前のフォルダーを作成しますlayout-land
  • 縦向きモードのレイアウトと同じ名前の xml を作成します ( に含まれていますres/layout) 。
  • 横向きモードの位置。

xmlファイル名が同じなので、アクティビティがコンテンツビューを設定するとき

setContentView (R.layout.my_layout);

代わりに、フォルダーのmy_layout.xmlファイルが使用されます。layout-land

また、Android ドキュメントのLayouts & Supporting Multiple Screensも読んでください。どちらも有用な情報があり、後者ではさまざまな修飾子 ( などlayout-land) について説明しています。

于 2013-02-12T22:18:34.370 に答える
0

相対的なレイアウトを使用して、マージンを増やしてボタンを水平方向に配置していますか? それはレイアウトがどのように機能するかを完全に理解していません。RelativeLayout を、方向が水平に設定された LinearLayout に置き換えることから始め、すべての余白を取り除きます。余白は、要素間の数ピクセルにする必要があります。レイアウトの仕組みに関する Android チュートリアルを読むことをお勧めします。

于 2013-02-12T22:18:48.530 に答える