BottomSheet中的viewpager滚动

时间:2016-09-18 09:05:15

标签: android android-fragments android-viewpager bottom-sheet

我正在制作带有标签式布局和标签栏的Android应用程序。在我的mainActivity中,我已经放了一个底页,因为我希望在我的主要活动的所有3个选项卡上访问它。 底部工作表布局中出现此问题。我希望能够在我的底页中有3个标签。我可以在我的底部工作表中使用标签栏获取查看寻呼机,以便点击并滑动以切换标签。但问题是整个底部页面布局也是垂直滚动。

我基本上创建了一个包含工具栏和视图寻呼机的父片段。并将该片段放在底部。水平滚动工作很好,即在我的底部工作表,如果我向左或向右滑动我能够切换标签,但问题是所有这是垂直滚动,即如果我向上滚动它看起来好像我的整个片段包含在底部的viewpager向上滚动,向上滚动无限可滚动。我不想那样。

这是代码

mainActivity.xml

<?xml version="1.0" encoding="utf-8"?>      <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:context="com.example.ansh.beatsmusic.MainActivity">
<LinearLayout
    android:id="@+id/test"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="50dp"
    android:weightSum="1">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_weight="1" />
</LinearLayout>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="true"
    android:background="@android:color/holo_orange_light"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    app:behavior_hideable="false"
    app:behavior_peekHeight="50dp"
    app:elevation="3dp"
    >
    <fragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.example.ansh.beatsmusic.Music_player_parent"/>

</android.support.v4.widget.NestedScrollView </android.support.design.widget.CoordinatorLayout>

我的父片段进入底部页面

<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:nestedScrollingEnabled="false"
tools:context="com.example.ansh.beatsmusic.Music_player_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/my_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/my_tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/my_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_weight="1 </android.support.design.widget.CoordinatorLayout>

我的mainActivity.java保持不变,即我没有改变任何与创建标签式活动时默认创建的android studio相同的内容

这是我的父片段.java

public class Music_player_parent extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

// my stuff
private TabLayout tblayout;
private ViewPager vpager;
private ViewPagerAdapterMusicParent adapter;

public Music_player_parent() {
    // Required empty public constructor
}

/**
 * Use this factory method to create a new instance of
 * this fragment using the provided parameters.
 *
 * @param param1 Parameter 1.
 * @param param2 Parameter 2.
 * @return A new instance of fragment Music_player_parent.
 */
// TODO: Rename and change types and number of parameters
public static Music_player_parent newInstance(String param1, String param2) {
    Music_player_parent fragment = new Music_player_parent();
    Bundle args = new Bundle();
    args.putString(ARG_PARAM1, param1);
    args.putString(ARG_PARAM2, param2);
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mParam1 = getArguments().getString(ARG_PARAM1);
        mParam2 = getArguments().getString(ARG_PARAM2);
    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view=inflater.inflate(R.layout.fragment_music_player_parent,container,false);
    vpager=(ViewPager) view.findViewById(R.id.my_viewpager);
    tblayout=(TabLayout) view.findViewById(R.id.my_tab_layout);
    adapter=new ViewPagerAdapterMusicParent(getChildFragmentManager(),getActivity(),vpager,tblayout);
    vpager.setAdapter(adapter);
    tblayout.setupWithViewPager(vpager);
    return view;
}}

这是父片段中视图寻呼机的页面适配器

ublic class ViewPagerAdapterMusicParent extends FragmentPagerAdapter {
private ViewPager viewPager;
private TabLayout tabLayout;
private Context context;
public ViewPagerAdapterMusicParent(FragmentManager fm,Context c,ViewPager vp,TabLayout tb){
    super(fm);
    context=c;
    viewPager=vp;
    tabLayout=tb;
}
@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0:
            return PlaceholderFragment.newInstance(1);
        case 1:
            return PlaceholderFragment.newInstance(2);
        case 2:
            return PlaceholderFragment.newInstance(3);
    }
    return PlaceholderFragment.newInstance(position + 1);
}

@Override
public int getCount() {
    return 3;
}
public CharSequence getPageTitle(int position) {
    switch (position) {
        case 0:
            return "SECTION 1";
        case 1:
            return "SECTION 2";
        case 2:
            return "SECTION 3";
    }
    return null;
}}

我已经尝试在我的父片段中逐个放置线性布局,即首先我将整个cordinator布局放在线性布局中,然后尝试将所有内容放在线性布局中的cordinator布局中。这删除了任何类型的滚动垂直以及horrizontal我无法看到视图寻呼机的子片段,即我无法从占位符片段看到文本

0 个答案:

没有答案