ViewPager中的片段不会滚动

时间:2015-10-20 18:42:50

标签: android material-design android-tablayout android-appbarlayout

我的Activity appBarLayout TabLayout应该覆盖屏幕的2/5,所以它是一个很大的AppBarLayout。我创建了它,制作了tabLayout并配置了viewPager并且它正在运行,但有三个问题我无法弄清楚如何解决:

  1. 如果没有此app:layout_behavior="@string/appbar_scrolling_view_behavior",则会在appBarLayout

  2. 旁边显示viewpager
  3. 每当我输入任何editTexts时,AppBarLayout都会显示全屏。

  4. 第二个片段的高度很高,应该向下滚动,但不是。

  5. 相关代码:

    appBarLayoutviewPager

    的活动
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/rootLayout"
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.AppBarLayout
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:minHeight="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    >
                    <TextView
                        android:id="@+id/title"
                        android:textSize="17sp"
                        android:text="@string/app_name"
                        android:textColor="@color/green_900"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                </android.support.v7.widget.Toolbar>
            <ImageView
                android:id="@+id/img"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="center"
                android:src="@drawable/logo_home"
                android:fitsSystemWindows="true"
                />
            <TextView
                android:id="@+id/txt_version"
                android:text="@string/app_version"
                android:textColor="@color/white"
                android:textSize="10sp"
                android:layout_below="@+id/img_logo"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
    
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                app:tabMode="fixed"
                app:layout_collapseMode="pin"
                app:tabIndicatorHeight="3dp"
                app:tabIndicatorColor="@color/light_green_a700"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </android.support.design.widget.AppBarLayout>
    
    
        <android.support.v4.view.ViewPager
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/white_background" />
    
    </android.support.design.widget.CoordinatorLayout>
    

    应滚动的第二页(Tab):

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:background="@color/white_background"
        android:layout_height="wrap_content">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="23dp"
            android:background="@color/white_background">
    
        <Button
            android:id="@+id/btn_facebook_register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/facebook_register"
            android:drawableLeft="@drawable/fb_logo"
            android:textSize="15sp"
            android:padding="5dp"
            android:layout_marginLeft="11dp"
            android:layout_marginRight="11dp"
            android:textColor="@color/white"
            android:background="@drawable/button_facebook_shape"/>
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <View
                android:layout_marginTop="20dp"
                android:id="@+id/white_line"
                android:background="@color/white"
                android:layout_width="match_parent"
                android:layout_height="0.5dp"/>
            <View
                android:background="@color/login_hint"
                android:layout_width="match_parent"
                android:layout_below="@+id/white_line"
                android:layout_height="0.5dp"/>
            <TextView
                android:layout_marginTop="20dp"
                android:textColor="@color/login_hint"
                android:background="@color/white_background"
                android:layout_width="wrap_content"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_centerVertical="true"
                android:text="o con tu mail..."/>
        </RelativeLayout>
    
    
        <EditText
            android:id="@+id/edt_register_name"
            android:layout_width="match_parent"
            android:background="@drawable/edit_text_shape"
            android:padding="20dp"
            android:textSize="15sp"
            android:maxLines="1"
            android:inputType="textCapWords"
            android:imeOptions="actionNext"
            android:textColorHint="@color/login_hint"
            android:hint="@string/txt_register_name"
            android:layout_height="wrap_content" />
    
        <EditText
            android:id="@+id/edt_register_lastname"
            android:layout_marginTop="15dp"
            android:padding="20dp"
            android:textSize="15sp"
            android:maxLines="1"
            android:inputType="textCapWords"
            android:imeOptions="actionNext"
            android:background="@drawable/edit_text_shape"
            android:layout_width="match_parent"
            android:textColorHint="@color/login_hint"
            android:hint="@string/txt_register_last_name"
            android:layout_height="wrap_content" />
    
    
    
        <EditText
            android:id="@+id/edt_register_email"
            android:layout_marginTop="15dp"
            android:padding="20dp"
            android:textSize="15sp"
            android:maxLines="1"
            android:imeOptions="actionNext"
            android:inputType="textEmailAddress"
            android:background="@drawable/edit_text_shape"
            android:layout_width="match_parent"
            android:textColorHint="@color/login_hint"
            android:hint="@string/txt_register_email"
            android:layout_height="wrap_content" />
        <EditText
            android:id="@+id/edt_register_pass"
            android:layout_marginTop="15dp"
            android:padding="20dp"
            android:textSize="15sp"
            android:maxLines="1"
            android:imeOptions="actionNext"
            android:inputType="textPassword"
            android:background="@drawable/edit_text_shape"
            android:layout_width="match_parent"
            android:textColorHint="@color/login_hint"
            android:hint="@string/txt_register_pass"
            android:layout_height="wrap_content" />
        <EditText
            android:id="@+id/edt_register_pss_conf"
            android:layout_marginTop="15dp"
            android:padding="20dp"
            android:textSize="15sp"
            android:maxLines="1"
            android:inputType="textPassword"
            android:imeOptions="actionDone"
            android:background="@drawable/edit_text_shape"
            android:layout_width="match_parent"
            android:textColorHint="@color/login_hint"
            android:hint="@string/txt_register_pass_confirm"
            android:layout_height="wrap_content" />
    
            <Button
                android:layout_marginTop="15dp"
                android:id="@+id/btn_register_done"
                android:text="@string/btn_register_done"
                android:drawableLeft="@drawable/kick"
                android:paddingLeft="30dp"
                android:textColor="@color/white"
                android:paddingTop="10dp"
                android:paddingBottom="10dp"
                android:textSize="15sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/button_done_shape"/>
        </LinearLayout>
    </ScrollView>
    

    ActivityviewPager

    的java代码
    public class LoginRegisterActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login);
    
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
            viewPager.setAdapter(new myFragmentPagerAdapter(getSupportFragmentManager(), LoginRegisterActivity.this));
    
            TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
            tabs.setupWithViewPager(viewPager);
        }
    
        public class myFragmentPagerAdapter extends FragmentPagerAdapter {
            final int PAGE_COUNT = 2;
            private String tabTitles[] = new String[]{"Ingresar", "Registrarse"};
            private Context context;
    
            public myFragmentPagerAdapter(FragmentManager fm, Context context) {
                super(fm);
                this.context = context;
            }
    
            @Override
            public int getCount() {
                return PAGE_COUNT;
            }
    
            @Override
            public Fragment getItem(int position) {
    
                switch (position) {
                    case 0:
                        return LoginFragment.newInstance(position);
                    case 1:
                        return RegisterFragment.newInstance(position);
                    default:
                        return null;
                }
    
            }
    
            @Override
            public CharSequence getPageTitle(int position) {
                // Generate title based on item position
                return tabTitles[position];
            }
        }
    

0 个答案:

没有答案