ScrollView不会使用TabLayout& ViewPager

时间:2015-10-13 16:44:29

标签: android android-layout android-fragments android-viewpager scrollview

我搜索了解决方案,但没有任何对我有用。当我打开应用程序一切正常但它不会滚动。如果我添加一个普通的片段,它会滚动,但不会使用viewpager。

This is my current App but I can't scroll Down!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="leon.myapplication.ProfileActivity"
    android:background="#000">


        <android.support.v4.widget.DrawerLayout
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:id="@+id/drawerlayoutgesamt"
            >
            <!-- Activity Layout-->
    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/activitylayout">


                    <RelativeLayout
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">

                        <RelativeLayout
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/header"
                            android:background="#fff">

                            <ImageView
                        android:src="@drawable/background_new1"
                        android:scaleType="centerCrop"
                        android:layout_width="wrap_content"
                        android:layout_height="200dp"
                        android:id="@+id/headerimageView"
                        />

                            <de.hdodenhof.circleimageview.CircleImageView
                        xmlns:app="http://schemas.android.com/apk/res-auto"
                        android:id="@+id/profile_image"
                        android:layout_width="120dp"
                        android:layout_height="120dp"
                        android:src="@drawable/profile"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true"
                        android:layout_alignParentTop="true"
                        android:layout_marginTop="130dp"
                        android:layout_marginLeft="24dp"
                        app:civ_border_width="0dp"
                        app:civ_border_color="#FF000000"/>

                        <LinearLayout
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:paddingTop="80dp"
                            android:layout_marginLeft="24dp"
                            android:layout_below="@+id/headerimageView"
                            android:orientation="vertical"
                            android:layout_marginBottom="16dp">
                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textAppearance="?android:attr/textAppearanceLarge"
                                android:text="Dein Vorname Nachname"
                                android:id="@+id/textViewname"
                                android:layout_weight="1" />

                            <TextView
                                android:layout_below="@+id/textViewname"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textAppearance="?android:attr/textAppearanceMedium"
                                android:text="Hier deine E-Mail Adresse"
                                android:id="@+id/textViewEmail" />
                            <LinearLayout
                                android:layout_width="300dp"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal">
                                <TextView
                                    android:layout_below="@+id/textViewEmail"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textAppearance="?android:attr/textAppearanceMedium"
                                    android:text="SonstigeInfo1"
                                    android:id="@+id/textViewInfo1"
                                    android:layout_weight="1" />

                                <TextView
                                    android:layout_below="@+id/textViewInfo1"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textAppearance="?android:attr/textAppearanceMedium"
                                    android:text="SonstigeInfo2"
                                    android:id="@+id/textViewInfo2"
                                    style="1" />
                            </LinearLayout>

                        </LinearLayout>





                        </RelativeLayout>
                        <RelativeLayout
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:id="@+id/rtablayout"
                            android:layout_below="@+id/header"
                            android:background="#fff">

                            <android.support.design.widget.TabLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:id="@+id/tablayout"
                                app:tabSelectedTextColor="#B71C1C"
                                app:tabIndicatorColor="#B71C1C"
                                app:tabTextColor="#757575"
                                android:theme="@style/toolbarstyle"
                                android:background="#E0E0E0" />


                            <android.support.v4.view.ViewPager
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/tablayout"
                                android:id="@+id/viewpager">


                                <LinearLayout
                                    android:orientation="vertical"
                                    android:layout_width="fill_parent"
                                    android:layout_height="fill_parent"
                                    android:id="@+id/Group"/>
                            </android.support.v4.view.ViewPager>




                        </RelativeLayout>


                    </RelativeLayout>


                <android.support.v7.widget.Toolbar
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/toolbar1"
                    android:background="@android:color/transparent"
                    android:fitsSystemWindows="true"
                    android:theme="@style/toolbarstyle" />

            </RelativeLayout>
    </ScrollView>
            <!-- Drawer Layout -->

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/drawerlayoutsingle"
                android:layout_gravity="start"
                android:background="#fff">
                <!-- Here everything for the DrawerLayout -->

                <android.support.design.widget.NavigationView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/navView"
                    app:itemIconTint="@color/itemtintcolor"
                    app:itemTextColor="@color/itemtintcolor"
                    app:menu="@menu/navigation_view_menue"
                    app:headerLayout="@layout/header_layout"
                    />


            </RelativeLayout>
        </android.support.v4.widget.DrawerLayout>


</RelativeLayout>

我的活动

//add Tablayout
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    final ViewPagerAdapter2 viewPagerAdapter2 = new ViewPagerAdapter2(getSupportFragmentManager());
    viewPager.setAdapter(viewPagerAdapter2);
    tabLayout = (TabLayout) findViewById(R.id.tablayout); //tabaylout
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); //tabs fill the width
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
       }

       @Override
      public void onTabUnselected(TabLayout.Tab tab) {
       }

        @Override
       public void onTabReselected(TabLayout.Tab tab) {
        }
    });

    //add FragmentHome
    //fHome = new FragmentHome();
    //android.support.v4.app.FragmentTransaction transaction = manager.beginTransaction();
    //transaction.add(R.id.Group, fHome, "fHome");
    //transaction.addToBackStack("addA");
    //transaction.commit();

    //add Navigation View
    drawerLayoutgesamt = (DrawerLayout) findViewById(R.id.drawerlayoutgesamt);
    drawerLayoutSingle = (RelativeLayout) findViewById(R.id.drawerlayoutsingle);
    drawerToggle = new ActionBarDrawerToggle(ProfileActivity.this,drawerLayoutgesamt,R.string.auf, R.string.zu);
    drawerLayoutgesamt.setDrawerListener(drawerToggle);

    drawerToggle.syncState(); // for Navigation View

    navView = (NavigationView) findViewById(R.id.navView);
    navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.drawerViewItem1:

                    break;
                case R.id.drawerViewItem2:

                    break;
                case R.id.drawerViewItem3:

                    break;
                case R.id.drawerViewItem4:

                    break;
            }
            navView.getMenu().getItem(0).setChecked(true);

            return false;
        }
    });

}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }
    if (drawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    drawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    drawerToggle.onConfigurationChanged(new Configuration());
}
public void loadPreferences(){
    Integer background;
    sharedPrefs = getSharedPreferences("prefsDatei1",MODE_PRIVATE);
    background = sharedPrefs.getInt("background", R.drawable.background_new1);
    if (background!=null){
        ImageView imageView = (ImageView) findViewById(R.id.headerimageView);
        imageView.setImageResource(background);}

}

我的ViewPagerAdapter

 public ViewPagerAdapter2(FragmentManager manager){
    super(manager);
}

@Override
public Fragment getItem(int position) {

    switch (position){

        case 0: return new FragmentGame();
        case 1: return new FragmentKalender();
        case 2: return new FragmentKalender();
    }


    return null;
}

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

@Override
public CharSequence getPageTitle(int position) {
    return tabtitlearray[position];
}

0 个答案:

没有答案