1

ランドスケープモードでタブレットをサポートするために、フラグメントを使用するように Android アプリを変換中です。

横向きモードのタブレットに並べて表示したいアクティビティが 2 つあります。現在、最初のアクティビティ (DisplayNotams) には、2 番目のアクティビティ (Chart) を表示するためのインテントを呼び出すボタンがあります。1 つ目は、ページャーを使用して一度に 1 つずつ表示する個々のアイテムのテキスト表示であり、2 つ目は、アイテムがプロットされたチャートです。

Chart は独自の ChartView を作成するため、xml レイアウト ファイルを使用しません。

ChartView mView;
mView = new ChartView(this, mCentreLat, mCentreLong, mRadius);
setContentView(mView);

(クラス ChartView は View を拡張し、ほとんどの描画コードを含みます。)

私は github のサンプル commonsguy/cw-omnibus/LargeScreen/EU4you を使用して、修正したコードのベースにしています。(私にとって) 問題は、これが layout と layout-large-land で異なるレイアウト xml ファイルを使用して、2 つを区別することです。DisplayNotams 用のレイアウト xml ファイルしかなく、Chart 用の xml ファイルがないため、どうすればよいか途方に暮れています。

この例を自分の状況に適応させる方法はありますか?

参考までに、EU4You の 2 つの xml ファイルは次のとおりです。

レイアウト:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/countries"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
/>

レイアウト大地の場合:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <FrameLayout
    android:id="@+id/countries"
    android:layout_weight="30"
    android:layout_width="0px"
    android:layout_height="fill_parent"
  />
  <FrameLayout
    android:id="@+id/details"
    android:layout_weight="70"
    android:layout_width="0px"
    android:layout_height="fill_parent"
  />
</LinearLayout>

「countries」は DisplayNotams に対応し、「details」は Chart に対応します。

答えてくれた人に感謝します。これは私が思いついたもので、置き換えます

ChartView mView;
mView = new ChartView(this, mCentreLat, mCentreLong, mRadius);
setContentView(mView);

ChartView mView;
mView = new ChartView(this, mCentreLat, mCentreLong, mRadius);
setContentView(R.layout.chart);
FrameLayout fl = (FrameLayout)findViewById(R.id.chart_frame);
fl.addView(mView);

新しい chart.xml ファイルを作成します。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <FrameLayout
        android:id="@+id/chart_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
4

2 に答える 2

1

を使用する代わりに、フラグメントクラスの-メソッドでsetContentView(mView)ChartViewを返すことができます。onCreateView

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            ChartView mView;
            mView = new ChartView(this, mCentreLat, mCentreLong, mRadius);
            return mView;
        }
于 2012-11-29T12:47:18.520 に答える
1

addViewで使用できる関数のグループがありますViewGroup。これを使用して、s に子を追加できますFrameLayout

ChartView mView;
mView = new ChartView(this, mCentreLat, mCentreLong, mRadius);

FrameLayout frame = (FrameLayout) findViewById(R.id.countries);
frame.addView(mView);
于 2012-11-29T12:41:16.183 に答える