我在其中有一个片段RecyclerView与LinearLayoutManager其中有CardView项目.点击时有一个浮动操作按钮,项目应滚动到顶部.我已经尝试使用scrollToPosition以及scrollToPositionWithOffset与RecyclerView和也LinearLayoutManager,如下图所示.但它根本没有效果.为什么会这样?任何人都可以帮助我.
我已将其RecyclerView直接放在SwipeRefreshViewxml文件中.我setFloatingActionButton一旦设置适配器就打电话给我RecyclerView.
public void setFloatingActionButton(final View view) {
float = (android.support.design.widget.FloatingActionButton) getActivity().findViewById(R.id.float);
float.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mRecyclerView.smoothScrollToPosition(0);
android.support.design.widget.Snackbar.make(view, "Scrolled to Top", android.support.design.widget.Snackbar.LENGTH_SHORT)
.setAction("Ok", new View.OnClickListener() {
@Override
public void onClick(View v) {
LinearLayoutManager llm = (LinearLayoutManager) mRecyclerView.getLayoutManager();
llm.scrollToPosition(0);
}
})
.setActionTextColor(getActivity().getResources().getColor(R.color.coloLink))
.show();
}
});
}
Run Code Online (Sandbox Code Playgroud) 我已在我的应用中实施了Admob原生广告.它已被放置为在我的recyler视图中每4个项目显示一次.
问题是:在显示广告之前,空白空间将显示大约3到5秒,直到加载广告.我需要帮助才能删除此空白空间,并仅在完全加载原生广告时在广告系列之间加载广告.我在下面附上了2个屏幕截图:显示广告之前和之后.
适配器代码如下所示.
public class MovieAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context mContext;
private List<Movie> mList;
private LayoutInflater mLayoutInflater;
private static final int DEFAULT_VIEW_TYPE = 1;
private static final int NATIVE_AD_VIEW_TYPE = 2;
public MovieAdapter(Context c, List<Movie> l) {
this(c, l, true, true);
}
public MovieAdapter(Context c, List<Movie> l, boolean wa, boolean wcl) {
mContext = c;
mList = l;
mLayoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getItemViewType(int position) {
if (position!=0 && position%4 == 0) {
return NATIVE_AD_VIEW_TYPE; …Run Code Online (Sandbox Code Playgroud) 我已经基于库https://github.com/Agraphie/hexagonloadingview使用了如下所示的六角加载器。但是我需要与上述库稍有不同的动画。像https://codepen.io/wuser/pen/BgPMqE
六边形视图动画代码
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
public class HexagonLoadingView extends View {
public static final int NUMBER_OF_HEXAGONS = 7;
/**
* Constants for changing the number of appearance/disappearance of the hexagons. {@link
* HexagonLoadingView#HEXAGON_UPPER_LEFT_APPEARANCE_POSITION} = 0 means the hexagon will start
* appearing in the upper left corner. {@link HexagonLoadingView#HEXAGON_MIDDLE_MIDDLE_APPEARANCE_POSITION}
* = 6 means this hexagon will appear last and disappear first.
*/
public static …Run Code Online (Sandbox Code Playgroud) 这是关于协调活动中浮动操作按钮的行为的问题,其中包含5个片段.
在我的应用程序中,我有一个Activity,它包含一个ViewPager和一个用FloatingActionButton定义的xml.ViewPager包含片段,每个片段内都有一个RecyclerView.On点击浮动操作按钮我实现了scrollToPosition(0).由于我在main活动的xml文件中实现了Floating ActionButton,因此scrollToPosition()仅在单击浮动操作按钮的最后一个片段中起作用.我如何克服这一点,以便在任何片段中点击浮动按钮时,回收器视图滚动到顶部?
我已经尝试在片段布局文件中实现了floatingactionbutton并且它完全正常.但是当我从一个片段滑动到另一个片段时,浮动动作按钮将会移动.所以有任何方法可以实现我在其中的浮动操作按钮.主活动xml文件,并且仍然能够在点击FloatingActionButton的每个片段中实现scrollToPosotion(0)?非常感谢任何建议.
以下是包含浮动操作按钮的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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f4f4f4"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/tb_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="0dp"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
<com.myapp.now.extras.SlidingTabLayout
android:id="@+id/sl_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
</com.myapp.now.extras.SlidingTabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_marginBottom="@dimen/fab_margin_bottom"
android:layout_marginEnd="@dimen/fab_margin_right"
android:layout_marginRight="@dimen/fab_margin_right"
android:clickable="true"
android:src="@mipmap/top_scroll"
app:backgroundTint="@color/colorFAB"
app:borderWidth="0dp"
app:fabSize="normal" />
Run Code Online (Sandbox Code Playgroud)
以下是片段的xml文件
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/srl_swipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list"
android:scrollbars="vertical"
android:fadeScrollbars="true"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
<ProgressBar
android:visibility="gone"
android:layout_gravity="center"
android:id="@+id/pbar"
android:layout_width="40dp" …Run Code Online (Sandbox Code Playgroud) android android-fragments android-activity floating-action-button android-recyclerview