簡體   English   中英

按鈕上帶有LinearLayout的Android ViewPager

[英]Android ViewPager with LinearLayout at the button

我有一個Activity,它使用ViewPager來瀏覽兩個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並指定布局,允許我在底部添加這樣的布局..任何人都可以幫助我嗎?

看起來您將內容視圖設置為mViewPager ,它不使用布局。

而不是創建新的ViewPager對象,使用您已創建的布局xml。 如果它被稱為activity_main.xml則通過setContentView(R.layout.activity_main);設置它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 >

弄清楚,只是正常使用setConentView,並通過id引用ViewPager ..不知道為什么我有這個問題..?

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

    setContentView(R.layout.application);

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

    mTabsAdapter = new OURSVPTabsAdapter(this, mViewPager);

    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM