2016-05-09 48 views
1

私は断片に対して1つの活性を有する。私はレイアウトを縦向きにするレイアウトと、横向きに並べるレイアウトにする方法を知らない。 2つのレイアウトを作成し、 "onCreate"メソッドでオリエンテーションをチェックし、適切なものをレンダリングする必要がありますか?レイアウトを違うように設定する必要がありますか? (今のところ、縦長ビューではOKですが、横長ビューでは重なっています)。ここで 2つの断片が画面上で異なることを示すアクティビティ

は私のレイアウトです:

<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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.apps.rucsi.biorhytm.MainActivity"> 

<fragment android:name="com.apps.rucsi.biorhytm.InputFragment" 
    android:id="@+id/inputFragment" 
    android:layout_weight="1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"/> 

<fragment android:name="com.apps.rucsi.biorhytm.OutputFragment" 
    android:id="@+id/outputFragment" 
    android:layout_weight="1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"/> 

結果は肖像画である:enter image description here

とlanscapeに彼らが重なっ:enter image description here

答えて

0

は、だからここで何が起こっているか、あなたが設定していることあなたの最上位のフラグメントを親の先頭に合わせるandroid:layout_alignParentTop="true"そして下のフラグメントをthに揃える親の底辺android:layout_alignParentBottom="true"。あなたは似合う肖像画だけで幸運です。

いくつかのことを行うことができます。これを2番目のフラグメントに追加すると、最初のフラグメントandroid:layout_toEndOf="@+id/inputFragment"が鳴っていることがわかります。

また、線形レイアウトにすることもできます。

+0

さて、私はそれらをLinearLayoutに入れました。縦向きに縦向き、横向きに横向きを設定しました。それはOKですが、これには2つのレイアウト(例:layoutとlayout_land)を使用する必要がありますか?私は両方の状況に合わせて1つのレイアウトを作る方法を理解できません。 – Rucsi

+0

あなたは垂直方向のみが必要です。あなたがあなたの携帯電話を回転させると「上がっている」ものも変化するので、これは別のlayout_landを必要としません。 – jbarat

+0

はい、私は下のグラフを望んでいませんが、私はそれをフォームの右側に入れます。垂直方向では、それを下に横に整列させます。私が何かを見逃してしまったのは残念ですが、私はAndroid開発で非常に新しいです。あなたの答えをありがとう! – Rucsi

関連する問題