7

我试图在 CollapsingToolbarLayout 中放置一个复杂的布局。附图描述了细节。

  • 我想要什么- 在我的 CollapsingToolbarLayout 中添加描述的自定义布局。
  • 有什么问题
  • CirclePageIndicator 不可见(截图如下)
  • ViewPager 在 ViewPager 中滑动会出现空白屏幕。这是尽管 PagerAdapter 配置的。
  • 任何将我的自定义布局带到 CollapsingToolbarLayout 之外并使其成为 AppBarLayout 的直接子级的任何尝试都会带来一个空白屏幕。
  • 我做了什么——
  • 尝试创建 CollapsingToolbarLayout 的子 LinearLayout - 这不显示 CirclePageIndicator 并且不一致地显示 ViewPager
  • 尝试创建 AppBarLayout 的子 LinearLayout - 这显示一个空白屏幕。

我该如何解决这个问题?

非常感谢任何帮助!

所需布局

activity_main.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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar_layout"
        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/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="@android:color/darker_gray"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true">

            <!--<ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/charts"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.1" />-->

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:background="@drawable/charts" >

                <android.support.v4.view.ViewPager
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

                <com.viewpagerindicator.CirclePageIndicator
                    android:id="@+id/circlePageInd"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

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

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

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        app:layout_anchor="@id/appbar_layout"
        app:layout_anchorGravity="bottom|right|end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Info
                Jarlsberg lancashire edam. Dolcelatte hard cheese brie st. agur blue
    cheese caerphilly bavarian bergkase cheese and biscuits mascarpone. Cheeseburger swiss bavarian
    bergkase cream cheese fromage frais cheesy feet port-salut airedale. St. agur blue cheese rubber
    cheese caerphilly cheddar cheesecake cream cheese manchego lancashire. Roquefort squirty cheese
    the big cheese."
                android:textAppearance="@style/TextAppearance.AppCompat.Title" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Jarlsberg lancashire edam. Dolcelatte hard cheese brie st. agur blue
    cheese caerphilly bavarian bergkase cheese and biscuits mascarpone. Cheeseburger swiss bavarian
    bergkase cream cheese fromage frais cheesy feet port-salut airedale. St. agur blue cheese rubber
    cheese caerphilly cheddar cheesecake cream cheese manchego lancashire. Roquefort squirty cheese
    the big cheese." />

        </LinearLayout>

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

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

MainActivity.java 包 com.deep.;

import android.content.res.Configuration;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TableLayout;

import com.viewpagerindicator.CirclePageIndicator;

import java.util.List;


public class MainActivity extends AppCompatActivity {

    private static final int VIEW_PAGER_COUNT = 3;

/*    private ListView listView;
    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle actionBarDrawerToggle;*/

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        toolbar.setBackgroundColor(Color.BLUE);
//        toolbar.setTitle("Wealth Tracker");
        setSupportActionBar(toolbar);

        final ActionBar ab = getSupportActionBar();
        ab.setTitle("WealthTracker");
        ab.setHomeAsUpIndicator(R.drawable.ic_drawer);
        ab.setDisplayHomeAsUpEnabled(true);

        ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
        ScreenSlidePagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);

        CirclePageIndicator circlePageIndicator = (CirclePageIndicator) findViewById(R.id.circlePageInd);
        circlePageIndicator.setViewPager(viewPager);


    }

    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

        public ScreenSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return new ScreenSlidePagerFragment();
        }

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

    public static class ScreenSlidePagerFragment extends Fragment {
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//            return super.onCreateView(inflater, container, savedInstanceState);

//            View view = inflater.inflate(R.layout.fragment_main, container, false);
//            return view;

            TabLayout tabLayout = new TabLayout(getActivity());
            tabLayout.addTab(tabLayout.newTab().setText("Expense"));
            tabLayout.addTab(tabLayout.newTab().setText("Inflow"));
            tabLayout.addTab(tabLayout.newTab().setText("Investment"));

            tabLayout.setTabMode(TabLayout.MODE_FIXED);
            tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
            tabLayout.setTabTextColors(Color.WHITE, Color.YELLOW);

            Log.i("ScreenSlidePagerFrag", "Returning tab layout");

            return tabLayout;
        }
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // If the nav drawer is open, hide action items related to the content view
//        boolean drawerOpen = drawerLayout.isDrawerOpen(listView);
//        menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @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.

//        if(actionBarDrawerToggle.onOptionsItemSelected(item)){ return true; }

        int id = item.getItemId();

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

        return super.onOptionsItemSelected(item);
    }
}
4

0 回答 0