【问题标题】:Android Fragment and Scrolling barAndroid 片段和滚动条
【发布时间】:2016-12-11 02:35:57
【问题描述】:

scrolling activity

我正在尝试使用片段(底部栏)进行此活动。

error page

但结果是这样的。 我删除了 style.xml (Light.NoActionBar) 中的操作栏,但它保留了空间。

这里是代码

activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:padding="16dp"
android:layout_height="match_parent">

SearchFragment.java

   @Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_search, container, false);

    //Toolbar
    final Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    AppCompatActivity activity = (AppCompatActivity) getActivity();

    activity.setSupportActionBar(toolbar);
    activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) view.findViewById(R.id.collapse_toolbar);
    collapsingToolbarLayout.setTitle("scrolling bar");

    return view;
}

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Bottom Tool Bar
    bottomBar = BottomBar.attach(this, savedInstanceState);

    bottomBar.setFragmentItems(getSupportFragmentManager(), R.id.fragmentContainer,
            new BottomBarFragment(SearchFragment.newInstance("Content for search."), R.drawable.ic_update_white_24dp, "검색"),
            new BottomBarFragment(SampleFragment.newInstance("Content for favorites."), R.drawable.ic_favorite_white_24dp, "관심 리스트"),
            new BottomBarFragment(SampleFragment.newInstance("Content for food."), R.drawable.ic_local_dining_white_24dp, "메시지"),
            new BottomBarFragment(SampleFragment.newInstance("Content for locations."), R.drawable.ic_location_on_white_24dp, "프로필")
    );

    // Setting colors for different tabs when there's more than three of them.
    bottomBar.mapColorForTab(0, "#3B494C");
    bottomBar.mapColorForTab(1, "#00796B");
    bottomBar.mapColorForTab(2, "#7B1FA2");
    bottomBar.mapColorForTab(3, "#FF5252");

    bottomBar.setOnItemSelectedListener(new OnTabSelectedListener() {
        @Override
        public void onItemSelected(int position) {
            switch (position) {
                case 0:
                    // Item 1 Selected
            }
        }
    });

activity_search.xml

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="10dp">

    <android.support.v7.widget.CardView
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textSize="20sp"
                android:text="test2"/>
        </LinearLayout>
    </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="20sp"
                    android:text="test1"/>
            </LinearLayout>
        </android.support.v7.widget.CardView>


    </LinearLayout>


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

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="pin" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin" />

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

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

【问题讨论】:

    标签: android xml scroll fragment


    【解决方案1】:

    转到清单 -> 将以下属性添加到 MainActivity 条目 -

    android:theme ="AppCompat.NoActionBar"
    

    【讨论】:

      猜你喜欢
      • 2013-12-03
      • 1970-01-01
      • 2012-10-28
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-02
      • 2020-12-01
      相关资源
      最近更新 更多