2016-07-12 29 views
0

Ich benutze JakeWharton 's ViewPagerIndicator auf meiner Landschaft App, aber ich denke, ich bin mit dem Layout zu schaffen. Der ViewPagerIndicator wird nicht angezeigt. Ich habe gerade begonnen, Android Development zu lernen, damit jede Hilfe geschätzt wird!ViewPagerIndicator wird nicht angezeigt

Meine Vermutung ist, dass es mit meinem linearen Layout zu tun hat ... sollte es relativ sein? Verberge ich den Pager-Indikator? Ich weiß, dass wenn ich den Indikator-Code über den View-Pager verschiebe, sehe ich den Indikator, aber alles andere ist weiß. Das Layout meines Fragments ist ein relatives Layout, dessen Höhe und Breite dem Elternteil entsprechen.

Meine App ist eine Aktivität mit Fragmenten.

Bearbeiten: Ich setze die Anzeigehöhe, um den Inhalt zu umhüllen, aber jetzt schwebt es oben auf dem Bildschirm. Wie kann ich es untergehen lassen?

My_Activity.java

public class MyActivity extends FragmentActivity { 

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

    ViewPager pager = (ViewPager) findViewById(R.id.viewPager); 
    MyPagerAdapter mAdapter = new MyPagerAdapter(getSupportFragmentManager()); 
    pager.setAdapter(mAdapter); 
    CirclePageIndicator circleInd = (CirclePageIndicator) findViewById(R.id.circles); 
    circleInd.setViewPager(pager); 
    circleInd.setStrokeColor(0xAA000000); 
    //circleInd.setCurrentItem(mAdapter.getCount() - 1); 
} 

private class MyPagerAdapter extends FragmentPagerAdapter { 
    public MyPagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    @Override 
    public Fragment getItem(int pos) { 
     switch (pos) { 
      case 0: return FirstFragment.newInstance("First"); 
      case 1: return SecondFragment.newInstance("Second"); 
      default: return FirstFragment.newInstance("First"); 
     } 
    } 

    @Override 
    public int getCount() { 
     return 2; 
    } 
} 
} 

und die XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.frontrowqa.myfirstapplication.MyActivity"> 


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

<com.viewpagerindicator.CirclePageIndicator 
    android:id="@+id/circles" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:padding="10dp" 
    android:layout_gravity="bottom" /> 

</LinearLayout> 

Und mein Fragment

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="20dp"> 

<EditText 
    android:id="@+id/PasscodeText" 
    android:layout_height="wrap_content" 
    android:inputType="textPersonName" 
    android:layout_width="fill_parent" 
    android:hint="Passcode" 
    android:backgroundTint="@android:color/black" /> 

<EditText 
    android:id="@+id/ipAddressText" 
    android:layout_below="@id/PasscodeText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="IP Address" 
    android:backgroundTint="@android:color/black" /> 

<EditText 
    android:id="@+id/intercomText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/ipAddressText" 
    android:hint="Intercom Event Number" 
    android:backgroundTint="@android:color/black"/> 

<TextView 
    android:id="@+id/tvFragFirst" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:textSize="26dp" 
    android:text="TextView" /> 

</RelativeLayout> 
+1

verwende relativ und setze 'android: layout_alignParentBottom =" true "' auf dem 'ViewPagerIndicator' –

+0

@hello_world das hat funktioniert! Vielen Dank! – Jason

Antwort

1

Legen Sie Ihre Aktivität xml wie folgt aus:

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


    <android.support.v4.view.ViewPager 
     android:id="@+id/viewPager" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

    <com.viewpagerindicator.CirclePageIndicator 
     android:id="@+id/circles" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:padding="10dp" /> 

</LinearLayout>