私はアンドロイドの開発(v4.0、API 14)が初めてで、オリエンテーションの変更を実装しませんでした。オリエンテーションの変更に関するビューのサイズ変更
私はマニフェストファイル android:configChanges="orientation|keyboardHidden|screenSize">
に以下の行を追加しました。しかしscreenSize
パラメータは、私が手動でこれらの2つのメソッドを記述する必要がありそう働いていないように見えます:
public void ChangetoLandscape() {
ed.setTranslationX(300.0f);
btnindex.setTranslationX(300.0f);
btngainer.setTranslationX(300.0f);
btnloser.setTranslationX(300.0f);
lsym.setTranslationX(200.0f);
ltable.setTranslationX(300.0f);
tv1.setTranslationX(290.0f);
tv2.setTranslationX(300.0f);
tv4.setTranslationX(300.0f);
mySimpleXYPlot.setScaleX(3.0f);
mySimpleXYPlot.setScaleY(0.8f);
mySimpleXYPlot.setPlotMarginLeft(50.0f);
mySimpleXYPlot.setTranslationX(60.0f);
mySimpleXYPlot.setTranslationY(-70.0f);
sv1.setTranslationY(-80.0f);
}
public void ChangetoPortrait() {
//NOTE THAT IF I DON'T WRITE BELOW CODE,
//SWITCHING TO PORTRAIT MODE AFTER LANDSCAPE MODE RUINS THE WHOLE LAYOUT.
ed.setTranslationX(-1.0f);
btnindex.setTranslationX(-1.0f);
btngainer.setTranslationX(-1.0f);
btnloser.setTranslationX(-1.0f);
lsym.setTranslationX(-1.0f);
ltable.setTranslationX(-1.0f);
tv1.setTranslationX(-1.0f);
tv2.setTranslationX(-1.0f);
tv4.setTranslationX(-1.0f);
mySimpleXYPlot.setScaleX(1.0f);
mySimpleXYPlot.setScaleY(1.0f);
mySimpleXYPlot.setPlotMarginLeft(1.0f);
mySimpleXYPlot.setTranslationX(-1.0f);
mySimpleXYPlot.setTranslationY(-1.0f);
sv1.setTranslationY(-1.0f);
}
を。
私はRelativeLayoutを使用していますので、各ビューを方向変更時の指定位置に手動で移動しています。
main.xml
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/MainLayout">"
<EditText
android:id="@+id/txt1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:hint="Search"
android:layout_marginLeft="220dp"
android:selectAllOnFocus="true"
android:cursorVisible="false" >
</EditText>
<Button
android:id="@+id/btnindex"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="Index"
android:layout_marginLeft="140dp"
android:layout_below="@id/txt1"
android:textSize="12dp"/>
<Button
android:id="@+id/btngainer"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="Gainer"
android:layout_below="@id/txt1"
android:layout_toRightOf="@id/btnindex"
android:textSize="12dp"/>
<Button
android:id="@+id/btnloser"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="Loser"
android:layout_below="@id/txt1"
android:layout_toRightOf="@id/btngainer"
android:textSize="12dp"/>
<TextView
android:id="@+id/tv1"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="100dp"
android:textStyle="bold"
android:gravity="center"
android:textSize="10dp"
android:textColor="#00ff00"
android:text="SYMBOL"/> <!-- 2 similar textviews -->
<ListView
android:id="@+id/ltable"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="70dp"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_below="@id/txt1">
</ListView>
<com.androidplot.xy.XYPlot
android:id="@+id/mySimpleXYPlot"
android:layout_width="140dp"
android:layout_height="200dp"
android:layout_alignTop="@+id/btnindex"
title="Index"/>
<ScrollView android:id="@+id/sv1"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginTop="250dp">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:orientation="vertical">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv1"
android:text="Scrollview Item 1"/> <!-- 5 similar textviews -->
</LinearLayout>
</ScrollView>
</RelativeLayout>
。
しかし、スクリーンショットの下で示したように、風景モードでは、
android plot
を使用してプロットしたグラフが正しく表示され取得されていません。これの背後にある理由は、setScaleX()
メソッドbcozsetWidth()
を使用したためです。私はグラフを伸ばして見せたくありません。代わりに、その幅を増やす必要があります。portrait mode
にScrollViewが正しく表示されていますが、landscape mode
には、100dpの高さに応じて表示されません。
編集: android:configChanges="orientation|screenSize"
、 にandroid:configChanges="orientation|keyboardHidden|screenSize"
を変更した後、私は風景モードに切り替えたとき、私はこれを取得:
ここにはいくつかの驚くべきことがあります。 「screenSizeパラメータが機能していません」と言ったら、どういう意味ですか? onConfigChanged()をオーバーライドして、これらのメソッドをonConfigChanged()から呼び出していますか?あなたがそうであれば、これはまさに起こるはずのものです。 第2に、RelativeLayoutをAbsoluteLayoutのように使用しているようです。 RelativeLayoutチュートリアルで読んだことを強くお勧めします。正しく実装されていれば、翻訳を行う必要はありません。すべてが世話をするべきです。 –
続き.. 第3に、ポットライドモードとランドスケープモードの異なるレイアウトを探しているようです。これが当てはまる場合は、layout-landとlayout-potraitの使用を検討する必要があります。 –
@VikramBodicherla 1.)私はonConfigChanged()をオーバーライドしていますが、私は 'ChangetoLandscape()'と 'ChangetoPortrait()'メソッドを呼び出しています。 ** screenSizeに関連するものは何もありません。 2)「RelativeLayout」を使って、間違っていることを簡単に説明できますか? 3)私は 'layout-land'と' layout-potrait'を使ってみましたが、**私は**望まない**活動を再現します** – GAMA