0

ViewPager を使用して 2 つの ListFragments をページングするアクティビティがあります。これはうまく機能します。

EditText、Button、および TextView を持ついくつかのタイプのレイアウトを下部に追加しようとしています。ListFragmentでスクロールするのではなく、画面の下部でこれを修正したい。

私の見解は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@color/white">

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

しかし、私はonCreateでこれを使用しているため

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);

    setContentView(mViewPager);
}

このビューは読まれていません。問題は、ViewPager を使用してレイアウトを指定する方法がわからないことです。これにより、そのようなレイアウトを下部に追加できます。誰か助けてもらえますか?

4

2 に答える 2

1

mViewPagerレイアウトを使用していない に コンテンツ ビューを設定しているようです。

新しい ViewPager オブジェクトを作成するのではなく、作成したレイアウト xml を使用します。呼び出された場合はactivity_main.xml、経由で設定しますsetContentView(R.layout.activity_main);

たぶん、このようなものですか?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@color/white">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/pager"
    android:orientation="horizontal"
>
<Button... your button here />
<TextView ... your text here />
</LinearLayout>

</RelativeLayout >
于 2012-08-05T18:28:26.983 に答える
1

setConentView を通常どおり使用し、ViewPager を id で参照するだけです..なぜこれに問題があったのかわかりません..?

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.application);

    mViewPager = (ViewPager) findViewById(R.id.pager);

    mTabsAdapter = new OURSVPTabsAdapter(this, mViewPager);

    ...
}
于 2012-08-06T02:57:58.290 に答える