Scrollview不会在viewpager中滚动

时间:2016-07-11 17:17:47

标签: android android-layout android-fragments uiscrollview

我有Viewpager有4个标签,我用片段实现每个标签。现在问题是我的第一个标签,里面有片段。它有一个滚动视图,我不知道它为什么不滚动。使用linearlayout实现scrollview,在linearlayout内部有不同的控件,如textview,imagebutton,而且我确信scrollview大于屏幕大小。

这是我的代码:

activity_user_profile.xml:

<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawerId"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/loginbg_opt"
        >



        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:title=" "

            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            app:layout_scrollFlags="scroll|enterAlways"
            >
            <LinearLayout
                android:layout_marginTop="20dp"
                android:layout_marginBottom="20dp"
                android:gravity="center_horizontal|center_vertical|center"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <de.hdodenhof.circleimageview.CircleImageView
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/imgUserProfile"

                    android:layout_width="96dp"
                    android:layout_height="96dp"
                    android:src="@drawable/non"
                    app:civ_border_width="2dp"
                    app:civ_border_color="#FFFFFF"/>
            <TextView

                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginRight="10dp"
                android:text="امیر احسان زیربندیان"
                android:textSize="20dp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                />
            </LinearLayout>
        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            app:tabSelectedTextColor="@android:color/background_dark"
            app:tabTextColor="@android:color/white"
            android:layout_height="?attr/actionBarSize"
            app:tabMode="fixed"
            app:tabGravity="fill"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


</android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#000000"
        android:fitsSystemWindows="true"

        >
        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"

            android:layout_height="match_parent">

            <FrameLayout
                android:layout_weight="0.1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/header_pic"
                >
                <ImageView
                    android:layout_width="match_parent"

                    android:scaleType="centerCrop"
                    android:layout_height="match_parent"
                    android:layout_alignParentTop="true"
                    android:src="@drawable/navigation_header_chef"/>
                <ImageView
                    android:layout_width="90dp"
                    android:layout_height="90dp"
                    android:src="@drawable/cutmypic1"
                    android:layout_gravity="bottom|left"
                    android:layout_marginBottom="30dp"
                    android:layout_marginLeft="10dp"
                    />
                <TextView
                    android:layout_gravity="bottom|left"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="androiddev1991@gmail.com"
                    android:textStyle="bold"
                    android:textSize="15sp"
                    android:paddingLeft="15dp"
                    android:textColor="@android:color/white"
                    android:paddingBottom="10dp"
                    />
            </FrameLayout>


            <LinearLayout
                android:layout_marginTop="20dp"
                android:layout_weight="0.9"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="match_parent">

                <RelativeLayout
                    android:layout_weight=".16"
                    android:orientation="horizontal"
                    android:onClick="openSecondActivity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    >
                    <ImageView
                        android:id="@+id/img"
                        android:layout_width="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_height="wrap_content"
                        android:src="@drawable/navigation_icon_viewlist"
                        android:padding="10dp"

                        />
                    <TextView
                        android:id="@+id/tvlstName"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20dp"
                        android:layout_marginRight="40dp"
                        android:layout_marginTop="10dp"
                        android:text="لیست غذاها"
                        android:textColor="@android:color/white"
                        android:layout_alignRight="@+id/img"

                        />
                </RelativeLayout>
                <RelativeLayout
                    android:layout_weight=".16"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"

                    >
                    <ImageView
                        android:id="@+id/img1"
                        android:layout_width="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_height="wrap_content"
                        android:src="@drawable/navigation_icon_history"
                        android:padding="10dp"

                        />
                    <TextView
                        android:id="@+id/tvlstName1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20dp"
                        android:layout_marginRight="40dp"
                        android:layout_marginTop="10dp"
                        android:text="دزفول"
                        android:textColor="@android:color/white"
                        android:layout_alignRight="@+id/img1"

                        />
                </RelativeLayout>
                <RelativeLayout
                    android:layout_weight=".16"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:onClick="openTouristActivity"
                    >
                    <ImageView
                        android:id="@+id/img2"
                        android:layout_width="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_height="wrap_content"
                        android:src="@drawable/navigation_icon_incognito"
                        android:padding="10dp"

                        />
                    <TextView
                        android:id="@+id/tvlstName2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20dp"
                        android:layout_marginRight="40dp"
                        android:layout_marginTop="10dp"
                        android:text="گردشگری"
                        android:textColor="#ffffff"
                        android:layout_alignRight="@+id/img2"

                        />
                </RelativeLayout>
                <RelativeLayout
                    android:layout_weight=".16"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:onClick="openContactActivity"
                    >
                    <ImageView
                        android:id="@+id/img3"
                        android:layout_width="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_height="wrap_content"
                        android:src="@drawable/navigation_header_icon"
                        android:padding="10dp"

                        />
                    <TextView
                        android:id="@+id/tvlstName3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20dp"
                        android:layout_marginRight="40dp"
                        android:layout_marginTop="10dp"
                        android:text="تماس با ما"
                        android:textColor="@android:color/white"
                        android:layout_alignRight="@+id/img3"

                        />
                </RelativeLayout>
                <RelativeLayout
                    android:layout_weight=".16"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:onClick="exitApp"
                    >
                    <ImageView
                        android:id="@+id/img4"
                        android:layout_width="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_height="wrap_content"
                        android:src="@drawable/navigation_icon_exit"
                        android:padding="10dp"

                        />
                    <TextView
                        android:id="@+id/tvlstName4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20dp"
                        android:layout_marginRight="40dp"
                        android:layout_marginTop="10dp"
                        android:text="خروج"
                        android:textColor="@android:color/white"
                        android:layout_alignRight="@+id/img4"

                        />
                </RelativeLayout>


            </LinearLayout>
        </LinearLayout>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

和片段xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        >

        <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="wrap_content"
            android:orientation="vertical"

            android:weightSum="1"
            tools:context=".FragmentProfile">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:background="@drawable/btnsave" />
            <!-- TODO: Update blank fragment layout -->
            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtUserLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtname"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:gravity="right"
                    android:hint="نام"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtLastLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#5f5f5f"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtLastName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:gravity="right"
                    android:hint="نام خانوادگی"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtEmailLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#5f5f5f"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtEmail"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:enabled="false"
                    android:gravity="right"
                    android:hint="ایمیل"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtPw1Layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#5f5f5f"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtPw1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:enabled="false"
                    android:gravity="right"
                    android:hint="پسورد"
                    android:inputType="textPassword"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtPw2Layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#5f5f5f"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtPw2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:enabled="false"
                    android:gravity="right"
                    android:hint="تکرار پسورد"
                    android:inputType="textPassword"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>




            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:onClick="PickDate"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/Datepicker"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="25/05/1991"

                    />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="تاریخ تولد:"
                    android:textAlignment="gravity"
                    android:textSize="20dp"
                    android:textStyle="bold" />
            </LinearLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtFavLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#5f5f5f"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtFav"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:enabled="false"
                    android:gravity="right"

                    android:hint="علاقه مندی های من:"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtFavLayout2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#5f5f5f"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtFav2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:enabled="false"
                    android:gravity="right"

                    android:hint="علاقه مندی های من:"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>
            <android.support.design.widget.TextInputLayout
                android:id="@+id/txtFavLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#5f5f5f"
                android:textColorHint="#5f5f5f">

                <EditText
                    android:id="@+id/txtFav1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/holo_blue_dark"
                    android:enabled="false"
                    android:gravity="right"

                    android:hint="علاقه مندی های من:"
                    android:textAlignment="gravity"
                    android:textColor="#5f5f5f" />
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>
    </ScrollView>

和片段java代码:

package com.example.android.chatroom;


import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;

import java.util.Calendar;


/**
 * A simple {@link Fragment} subclass.
 */
public class FragmentProfile extends android.support.v4.app.Fragment  {

public  static TextView textView;
    public FragmentProfile() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.fragment_profile, container, false);
        textView = (TextView) v.findViewById(R.id.Datepicker);
        // Inflate the layout for this fragment
        return v;
    }
    public static void setText(String text){

        textView.setText(text);
    }


}

0 个答案:

没有答案