ViewPager和静态Facebook登录同一页面

时间:2015-12-28 01:30:11

标签: android facebook android-viewpager

对于我的程序,我决定做一个像登录页面那样的火种,顶部有一个可跳过的屏幕部分,底部有一个静态部分,它将容纳Facebook登录按钮。

我设法让刷卡独立工作,以及按钮的登录功能。但是,当我尝试在同一页面上包含这两个功能时,它既不会显示Viewpager,也不会简单地崩溃。

我认为它在我的xml中,但我不完全确定如何继续。

主要活动XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="fill_parent">

<android.support.v4.view.ViewPager
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    tools:context=".ScreenSliderActivity"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

    <fragment
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:name="com.Focalpoint.Views.LoginButtonFragment"
    android:id="@+id/fragment"
    tools:layout="@layout/login_section_fragment"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/view_pager" />

</RelativeLayout>

登录按钮XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LoginActivity" >


<TextView
    android:id="@+id/text_details"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_button"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

<com.facebook.login.widget.LoginButton
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|bottom"
    android:layout_marginBottom="48dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />


</FrameLayout>

ScreenSliderActivity:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;



public class ScreenSliderActivity extends FragmentActivity{


/** paper widget which handles the animation */
private ViewPager mviewPager;


/** paper widget which supplies the pages to the view page */
private PagerAdapter mpagerAdapter;


@Override
protected void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    mviewPager = (ViewPager) findViewById(R.id.view_pager);
    mpagerAdapter = new
    ScreenSlidePagerAdapter(getSupportFragmentManager());
    mviewPager.setAdapter(mpagerAdapter);
    mviewPager.setCurrentItem(0);

}

}


class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

public ScreenSlidePagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {
    switch(position) {
        case 0:
            return new FirstTutorialFragment();
        case 1:
            return new SecondTutorialFragment();
    }
return null;
}

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

0 个答案:

没有答案