2014-03-03 32 views
1

這裏是我的佈局是這樣的:我的ViewPagerIndicator在哪裏?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

    <com.viewpagerindicator.LinePageIndicator 
     android:id="@+id/titles" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_below="@id/pager" 
     android:background="#808080"/> 

</RelativeLayout> 

和我的onCreate()基礎上的示例代碼片段在網站上:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     pager = (ViewPager) findViewById(R.id.pager); 
     adapter = new ScreenSlideAdapter(getSupportFragmentManager()); 
     pager.setAdapter(adapter); 

     lineIndicator = (LinePageIndicator)findViewById(R.id.titles); 
     lineIndicator.setViewPager(pager); 


    } 

當我運行的應用程序,該指示燈不可見。我究竟做錯了什麼 ?

回答

3

試試這個隊友:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.viewpagerindicator.LinePageIndicator 
     android:id="@+id/titles" 
     android:layout_alignParentBottom="true" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:background="#808080"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/titles" /> 

</RelativeLayout> 
+0

是否奏效? –

+0

是的,它確實工作。你在這裏改變了什麼?另外,我怎樣才能使指標略大? –

4

系統從XML文件的頂部到底部讀取元素,以便您的ViewPager在系統知道ViewPagerIndicator需要在它之前填充整個高度。交換順序和使用layout_above代替:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.viewpagerindicator.LinePageIndicator 
     android:id="@+id/titles" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:background="#808080"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/titles" /> 

</RelativeLayout> 
+0

'11月3日至3日:44:12.119:E/AndroidRuntime (11417):java.lang.RuntimeException:無法啓動活動ComponentInfo {com.example.viewpager_testproject/com.example.viewpager_testproject.MainActivity}:java.lang.ClassCastException:com.viewpagerindicator.LinePageIndicator無法轉換爲android.support。 v4.vi ew.ViewPager' :-( –

+0

你確定要交換'android:id's? – ianhanniballake

+0

我複製粘貼你的XML。它看起來是正確的: -/ –

1

使用此...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

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

<com.viewpagerindicator.LinePageIndicator 
    android:id="@+id/titles" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/pager" 
    android:background="#808080" /> 

</RelativeLayout>