0

我有一个活动,使用ViewPager通过两个ListFragments页面 - 这很好。Android的ViewPager与LinearLayout在按钮

我正试图添加一些类型的底部有一个EditText,一个按钮和一个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并指定布局,允许我在底部添加这样的布局..任何人都可以帮助我?

回答

1

想通了,只要使用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); 

    ... 
} 
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 > 
+0

我试过这个,但随后的ViewPager does not工作:( – Rabbott 2012-08-05 18:44:32

+0

也许您正在使用附加适配器活动代码发布到寻呼机?还什么不工作? – scottyab 2012-08-05 18:53:16

+0

什么你的建议是正确的,但没有设置viewpager viewpager没有工作,我不得不将它设置在tabsadapter ..你的答案是在那里的一半 – Rabbott 2012-08-06 02:58:49