相关疑难解决方法(0)

Android:我无法拥有ViewPager WRAP_CONTENT

我已经设置了一个简单的ViewPager,每页都有一个高度为200dp的ImageView.

这是我的寻呼机:

pager = new ViewPager(this);
pager.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
pager.setBackgroundColor(Color.WHITE);
pager.setOnPageChangeListener(listener);
layout.addView(pager);
Run Code Online (Sandbox Code Playgroud)

尽管将高度设置为wrap_content,但即使imageview仅为200dp,寻呼机也会填充屏幕.我试图用"200"替换寻呼机的高度,但这给了我多种分辨率的不同结果.我无法将"dp"添加到该值.如何在寻呼机的布局中添加200dp?

android

245
推荐指数
11
解决办法
10万
查看次数

动态无尽RecyclerView滚动问题

我必须创建以下布局 在此输入图像描述

到目前为止,我已经成功创建了布局并填充了所有视图.但是,我在第一个片段制作ReyclerView Endless时遇到了问题.

考虑到RecyclerView在首次加载时有10个项目,现在滚动我正在添加另外10个项目,依此类推.然而,RecyclerView没有显示那些项目,它的高度在第10个元素的末尾得到修复.我知道元素在RecyclerView中正确加载,如果我尝试用两个手指在模拟器(GenyMotion)上滚动,RecyclerView滚动就好了.

更新: -

RecyclerView的片段代码 -

public class CheckInFragmentRecyclerAdapter extends RecyclerView.Adapter<CheckInFragmentRecyclerAdapter.ViewHolder> {
    final List<StoreNew> stores;

    public CheckInFragmentRecyclerAdapter(final List<StoreNew> stores) {
        this.stores = stores;
    }

    @Override
    public CheckInFragmentRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.child_check_in_fragment, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CheckInFragmentRecyclerAdapter.ViewHolder holder, int position) {
        // Setting data
    }


    @Override
    public int getItemCount() {
        return stores.size();
    }

    /**
     * Function to clear existing data from list
     * @param stores StoreNew instance containing …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview endlessscroll android-recyclerview

11
推荐指数
1
解决办法
2545
查看次数

使用NestedScrollView中的Viewpager折叠toolBar布局

我在嵌套的Scrollview中使用带有NestedScrollView和Viewpager的Collapsing ToolBar Layout.

我有3个标签,这些标签有3个片段.这些片段使用RecyclerView来设置数据.

现在使用nestedScrollView和viewpager,当我滚动RecyclerView内容时,折叠效果不适用于此.

我还需要放置NestedScrollView,因为我需要在Tabs上面显示一些信息.

这是我的代码:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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"
    android:fitsSystemWindows="true"
    app:contentScrim="?attr/colorPrimary"
    app:expandedTitleMarginEnd="64dp"
    app:expandedTitleMarginStart="48dp"
    app:expandedTitleTextAppearance="@style/TransparentText">

    <FrameLayout
        android:id="@+id/carouselLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:layout_collapseMode="parallax">

        <ImageView
            android:id="@+id/coverImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/example"
            android:scaleType="centerCrop"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:gravity="bottom"
            android:orientation="vertical"
            android:layout_gravity="bottom"
            android:padding="@dimen/profile_image_margin"
            android:background="@drawable/gradient_bg"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_height="wrap_content">

            <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/profile_image_margin"
            android:textSize="@dimen/text_size_xlarge"
            android:textStyle="bold"
            android:textColor="@color/white"
            android:text="Title"
            android:id="@+id/content_title"/>

        </LinearLayout>

    </FrameLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:theme="@style/ActionBarThemeOverlay"
            app:popupTheme="@style/ActionBarPopupThemeOverlay"
            app:layout_scrollFlags="scroll|enterAlways"
            android:background="@drawable/gradient_bg" />

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill"
    android:isScrollContainer="true"
    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" …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager android-collapsingtoolbarlayout

7
推荐指数
1
解决办法
9657
查看次数

如何在NestedScrollView中使用RecyclerView创建ViewPager

我在ViewPager中使用NestedScrollView.NestedScrollView里面有一个LinearLayout,最后有一些TextViews,TabLayout和ViewPager.TextViews占据了大部分空间,并为ViewPager留下了一点空间.ViewPager使用两个片段,其中一个有几个TextViews和ImageViews,另一个片段中有一个RecyclerView.

当我设置ViewPager的高度时,WRAP_CONTENT它只占用剩余的空间,我无法滚动查看第一个片段的其余部分,以及第二个片段scoll里面的小ViewPager.

例如,当我将ViewPager的高度设置为1000dp时,我可以向下滚动第一个片段,但第二个片段仍在小型ViewPager中滚动.在我用第一个Fragment中的RecyclerView scoll滚动片段后不再工作了.

如何解决滚动问题并使ViewPager工作WRAP_CONTENT

这是我的代码:

<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

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

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

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/mainBackground"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="SOME TEXT" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="SOME TEXT" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="SOME TEXT" />

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

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

        </LinearLayout>

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

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-viewpager android-recyclerview

7
推荐指数
2
解决办法
4113
查看次数

ScrollView内的ViewPager无法正常工作

我想在ViewPager里面放CoordinatorLayout一个NestedScrollView.viewpager有3个片段.

问题是片段不可见.选项卡显示,其余布局可见,并相应滚动.

以下是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical">

    <include layout="@layout/toolbar" />

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorLayout"
        android:layout_below="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/DarkBodyBackground"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

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

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:background="@color/DarkBodyBackground"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <include layout="@layout/artist_header" />

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

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

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

                <include layout="@layout/loading_indicator" />

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabLayout"
                    style="@style/TabLayoutStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:tabGravity="fill"
                    app:tabMode="fixed" />

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

            </RelativeLayout>
        </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout> …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-viewpager

7
推荐指数
3
解决办法
9555
查看次数

AppBarLayout 在以编程方式滚动期间不会折叠

我有一个带有 Fragments 的 ViewPager,其中包含 RecyclerViews。CollapsingTollbarLayout 位于 ViewPager 上方。除了在 RecyclerView 上以编程方式滚动之外,一切都工作正常。然后 AppBarLayout 或 CollapsingToolbarLayout 没有响应。

这是我的基本布局 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"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="256dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:layout_behavior="de.wackernagel.playball.ui.FlingBehaviour">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:id="@+id/collapsingToolbarLayout"
        app:contentScrim="?attr/colorPrimary"
        app:titleEnabled="false"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:contentDescription="@null"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/showdown"
            app:layout_collapseMode="parallax"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/doubleActionBarSize"
            android:minHeight="?attr/actionBarSize"
            android:gravity="top"
            app:titleMarginTop="14dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent"
            android:layout_gravity="bottom"
            app:tabTextColor="#BEFFFFFF"
            app:tabSelectedTextColor="#FFFFFFFF"
            app:tabContentStart="@dimen/keyline_2"
            app:tabMode="scrollable" />

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

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

<android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
Run Code Online (Sandbox Code Playgroud)

我的目标是在像普通触摸滚动一样以编程方式滚动期间折叠 CollapsingToolbarLayout。

我这样做是通过

Activity get …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview androiddesignsupport android-collapsingtoolbarlayout

4
推荐指数
1
解决办法
3903
查看次数

ViewPager不显示片段

我无法使它正常工作。基本应用程序可以正常运行,但是其中一个布局文件上的ViewPager根本不显示任何片段。我多次检查代码,但找不到错误。当我尝试调试它时,我注意到它甚至都没有初始化您选择选项卡时应该使用的片段类。我的主要活动:

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    new GetData(this).execute();

    TabLayout tab_layout = (TabLayout) findViewById(R.id.tab_layout);
    tab_layout.addTab(tab_layout.newTab().setText("CASUAL"));
    tab_layout.addTab(tab_layout.newTab().setText("RANKED"));
    tab_layout.setTabGravity(TabLayout.GRAVITY_FILL);

    final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), tab_layout.getTabCount());
    viewPager.setAdapter(adapter);
    tab_layout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
        } …
Run Code Online (Sandbox Code Playgroud)

android android-fragments

2
推荐指数
2
解决办法
2905
查看次数