Java Code Examples for android.support.v7.widget.RecyclerView#setHasFixedSize()

The following examples show how to use android.support.v7.widget.RecyclerView#setHasFixedSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SampleMapSnapshot.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
    mMapSize = Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels);
    mBorderSize = mMapSize / 15;

    mScaleBarOverlay = new ScaleBarOverlay(getActivity(), mMapSize, mMapSize);
    mScaleBarOverlay.setCentred(true);
    mScaleBarOverlay.setScaleBarOffset(mMapSize / 2, 10);

    final RecyclerView recyclerView = new RecyclerView(getActivity());
    recyclerView.setHasFixedSize(true);

    final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);

    try {
        final DataRegionLoader dataRegionLoader = new DataRegionLoader(getActivity(), R.raw.data_region_usstates);
        mAdapter = new MyAdapter(new ArrayList<>(dataRegionLoader.getList().values()));
        recyclerView.setAdapter(mAdapter);
    } catch(Exception e) {
        // DataRegionLoader KO, not supposed to happen
    }

    return recyclerView;
}
 
Example 2
Source File: PlanTaskListFragment.java    From friendly-plans with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

    Bundle arguments = getArguments();
    if (arePlanArgumentProvided(arguments)) {
        planId = (Long) arguments.get(ActivityProperties.PLAN_ID);
        typeId = (Integer) arguments.get(ActivityProperties.TYPE_ID);
    }

    TaskType taskType = TaskType.getTaskType(typeId);
    Button addButton = (Button) view.findViewById(R.id.id_btn_create_plan_add_tasks);
    TextView labelInfo = (TextView) view.findViewById(R.id.id_tv_plan_tasks_list_info);
    addButton.setText(taskType.getAddLabel());
    labelInfo.setText(taskType.getTaskListInfoLabel());

    RecyclerView recyclerView = (RecyclerView) getActivity()
            .findViewById(R.id.rv_create_plan_task_list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    taskListAdapter = new TaskRecyclerViewAdapter(taskItemClickListener);
    recyclerView.setAdapter(taskListAdapter);

    taskListAdapter
            .setTaskItems(planTemplateRepository.getTaskWithThisPlanByTypeId(planId, typeId));
}
 
Example 3
Source File: RecyclerViewFragment.java    From admob-native-advanced-feed with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_recycler_view, container, false);
    RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);

    // Use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView.
    mRecyclerView.setHasFixedSize(true);

    // Specify a linear layout manager.
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
    mRecyclerView.setLayoutManager(layoutManager);

    // Specify an adapter.
    RecyclerView.Adapter adapter = new RecyclerViewAdapter(getActivity(), mRecyclerViewItems);
    mRecyclerView.setAdapter(adapter);

    return rootView;
}
 
Example 4
Source File: InstalledAppsActivity.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    ((FDroidApp) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.installed_apps_layout);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.installed_apps__activity_title));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    adapter = new InstalledAppListAdapter(this);

    appList = (RecyclerView) findViewById(R.id.app_list);
    appList.setHasFixedSize(true);
    appList.setLayoutManager(new LinearLayoutManager(this));
    appList.setAdapter(adapter);

    emptyState = (TextView) findViewById(R.id.empty_state);
}
 
Example 5
Source File: SecondActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second_main);
    recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    recyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(mLayoutManager);

    List<TemperatureData> items =
            Arrays.asList(new TemperatureData("Hamburg", "5"), new TemperatureData("Berlin", "6"));

    // define an adapter
    mAdapter = new MyAdapter(items);
    recyclerView.setAdapter(mAdapter);
}
 
Example 6
Source File: TimeLineActivity.java    From Timeline with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_timeline);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if(getSupportActionBar()!=null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mOrientation = (Orientation) getIntent().getSerializableExtra(MainActivity.EXTRA_ORIENTATION);
    mWithLinePadding = getIntent().getBooleanExtra(MainActivity.EXTRA_WITH_LINE_PADDING, false);

    setTitle(mOrientation == Orientation.HORIZONTAL ? getResources().getString(R.string.horizontal_timeline) : getResources().getString(R.string.vertical_timeline));

    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mRecyclerView.setLayoutManager(getLinearLayoutManager());
    mRecyclerView.setHasFixedSize(true);

    initView();
}
 
Example 7
Source File: UiUtils.java    From Aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 配置recycleview
 *
 * @param recyclerView
 * @param layoutManager
 */
public static void configRecycleView(final RecyclerView recyclerView
        , RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
 
Example 8
Source File: OnlyLoadingActivity.java    From EasyRefreshLayout with Apache License 2.0 5 votes vote down vote up
private void initView() {
    easyRefreshLayout = (EasyRefreshLayout) findViewById(R.id.easylayout);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    layoutManager = new LinearLayoutManager(this);
    layoutManager.setAutoMeasureEnabled(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    adapter = new SimpleAdapter();
   // adapter.setDuration(1000);
   // adapter.openLoadAnimation(new MyAnimation());
    recyclerView.setAdapter(adapter);
    //scrollView = (ScrollView) findViewById(R.id.scrollview);
}
 
Example 9
Source File: ListActivity.java    From Learning-Resources with MIT License 5 votes vote down vote up
private void createReference() {
    RecyclerView listContact = (RecyclerView) findViewById(R.id.list_contact);
    listContact.setHasFixedSize(false);
    listContact.setLayoutManager(new LinearLayoutManager(activity));
    adapter = new ContactInfoAdapter(activity, new ArrayList<ContactInfoModel>());
    listContact.setAdapter(adapter);
    listContact.addItemDecoration(new HorizontalDividerItemDecoration.Builder(activity)
            .colorProvider(adapter)
            .build());
}
 
Example 10
Source File: HomeFragment.java    From NHentai-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
	View view = inflater.inflate(R.layout.fragment_home, container, false);

	mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
	mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
	mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
	mRecyclerView.setLayoutManager(mLayoutManager);
	mRecyclerView.setHasFixedSize(true);

	mBooks = new ArrayList<>();
	mAdapter = new BookListRecyclerAdapter(mRecyclerView, mBooks);
	setRecyclerViewAdapter(mAdapter);

	mSwipeRefreshLayout.setColorSchemeResources(
			R.color.deep_purple_500, R.color.pink_500, R.color.orange_500, R.color.brown_500,
			R.color.indigo_500, R.color.blue_500, R.color.teal_500, R.color.green_500
	);
	mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
		@Override
		public void onRefresh() {
			if (!mSwipeRefreshLayout.isRefreshing()) {
				mSwipeRefreshLayout.setRefreshing(true);
			}

			mBooks = new ArrayList<>();
			mAdapter = new BookListRecyclerAdapter(mRecyclerView, mBooks);
			setRecyclerViewAdapter(mAdapter);
			new PageGetTask().execute(mNowPage = 1);
		}
	});

	new PageGetTask().execute(mNowPage);

	return view;
}
 
Example 11
Source File: Home.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onPostExecute(Void aVoid) {
    bar.setVisibility(View.GONE);
    homeRecyclerView = (RecyclerView) findViewById(R.id.home_recycler_view);
    homeRecyclerView.setHasFixedSize(true);
    homeRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,1));
    homeAdapter = new HomeRecyclerView(conferences);
    homeRecyclerView.setAdapter(homeAdapter);
}
 
Example 12
Source File: HalfRightDragSwipeFragment.java    From swipe-maker with Apache License 2.0 5 votes vote down vote up
private void initRecyclerView(View view) {
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    mAdapter = new HalfRightDragSwipeAdapter(Album.getAlbum());
    mAdapter.setOnItemDismissListener(this);
    recyclerView.setAdapter(mAdapter);
}
 
Example 13
Source File: RecyclerViewFragment.java    From AndroidMaterialDesign with Apache License 2.0 5 votes vote down vote up
@Override
public void initViews(View view) {
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(recyclerView.getContext());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setAdapter(new RecyclerAdapter(list));

}
 
Example 14
Source File: GridLayoutAutoFitActivity.java    From android-recyclerview with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_auto_fit_recycler_view);
  RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
  recyclerView.addItemDecoration(new MarginDecoration(this));
  recyclerView.setHasFixedSize(true);
  recyclerView.setAdapter(new NumberedAdapter(30));
}
 
Example 15
Source File: ArmsUtils.java    From Aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 配置 RecyclerView
 *
 * @param recyclerView
 * @param layoutManager
 */
public static void configRecyclerView(final RecyclerView recyclerView
        , RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
 
Example 16
Source File: ListViewActivity.java    From Airbnb-Android-Google-Map-View with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_view);

    getSupportActionBar().setTitle("List View");
    mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_lisiting);

    mLoadingMoreDataProgress = (ProgressBar) findViewById(R.id.loading_progress);


    mLoadingMoreDataProgress.getIndeterminateDrawable().setColorFilter(0xff00b1c7, PorterDuff.Mode.MULTIPLY);
    mLoadingMoreDataProgress.setVisibility(View.GONE);


    mRecyclerView.setHasFixedSize(false);
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new ListViewAdapter(mAddressList, this);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.requestLayout();

    mSwipeLayout.setColorSchemeResources(R.color.gomalan_bule_bg);

    mAddressModel=new AddressModel(this, new BaseInterface() {
        @Override
        public void handleNetworkCall(Object object, int requestCode) {
            if (requestCode == NetworkConstants.ADDRESS_REQUEST) {
                if (object instanceof ArrayList) {
                    mAddressList = new ArrayList<>();
                    mAddressList = (ArrayList) object;
                    mAdapter = new ListViewAdapter(mAddressList, ListViewActivity.this);
                    mRecyclerView.setAdapter(mAdapter);
                    mAdapter.notifyDataSetChanged();
                }
                else{
                    Toast.makeText(ListViewActivity.this, (String)object,Toast.LENGTH_LONG).show();
                }
            }
        }
    });



    mAddressModel.fetchAddressFromServer();

}
 
Example 17
Source File: ViewPagerDemoActivity.java    From SwipeRefreshLayout with Apache License 2.0 4 votes vote down vote up
private void setupViewPagerViews() {
    mRecyclerView = new RecyclerView(this);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new GridLayoutManager(this, 2);

    mRecyclerView.setLayoutManager(mLayoutManager);

    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
        Drawable mDivider;

        {
            final TypedArray a = ViewPagerDemoActivity.this.obtainStyledAttributes(new int[]{android.R.attr.listDivider});
            mDivider = a.getDrawable(0);
            a.recycle();
        }

        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDraw(c, parent, state);
            final int left = parent.getPaddingLeft();
            final int right = parent.getWidth() - parent.getPaddingRight();

            final int childCount = parent.getChildCount();
            for (int i = 0; i < childCount; i++) {
                final View child = parent.getChildAt(i);
                final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                        .getLayoutParams();
                final int top = child.getBottom() + params.bottomMargin;
                final int bottom = top + mDivider.getIntrinsicHeight();
                mDivider.setBounds(left, top, right, bottom);
                mDivider.draw(c);
            }
        }
    });

    // specify an adapter (see also next example)
    mRecyclerViewAdapter = new MyAdapter(Cheeses.randomList(LIST_ITEM_COUNT));
    mRecyclerView.setAdapter(mRecyclerViewAdapter);

    mListView = new ListView(this);
    mListAdapter = new ArrayAdapter<String>(
            this,
            R.layout.demo_list_item,
            R.id.item_text,
            Cheeses.randomList(LIST_ITEM_COUNT));

    mListView.setAdapter(mListAdapter);


    viewPagerViews.add(mListView);
    viewPagerViews.add(mRecyclerView);
    viewPagerTitles.add("ListView");
    viewPagerTitles.add("RecyclerView");
}
 
Example 18
Source File: MainActivity.java    From spotify-web-api-android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = getIntent();
    String token = intent.getStringExtra(EXTRA_TOKEN);

    mActionListener = new SearchPresenter(this, this);
    mActionListener.init(token);

    // Setup search field
    final SearchView searchView = (SearchView) findViewById(R.id.search_view);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mActionListener.search(query);
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });


    // Setup search results list
    mAdapter = new SearchResultsAdapter(this, new SearchResultsAdapter.ItemSelectedListener() {
        @Override
        public void onItemSelected(View itemView, Track item) {
            mActionListener.selectTrack(item);
        }
    });

    RecyclerView resultsList = (RecyclerView) findViewById(R.id.search_results);
    resultsList.setHasFixedSize(true);
    resultsList.setLayoutManager(mLayoutManager);
    resultsList.setAdapter(mAdapter);
    resultsList.addOnScrollListener(mScrollListener);

    // If Activity was recreated wit active search restore it
    if (savedInstanceState != null) {
        String currentQuery = savedInstanceState.getString(KEY_CURRENT_QUERY);
        mActionListener.search(currentQuery);
    }
}
 
Example 19
Source File: MatchesActivity.java    From TinderClone with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_matches);

    cusrrentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid();

    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mRecyclerView.setNestedScrollingEnabled(false);
    mRecyclerView.setHasFixedSize(true);
    mMatchesLayoutManager = new LinearLayoutManager(MatchesActivity.this);
    mRecyclerView.setLayoutManager(mMatchesLayoutManager);
    mMatchesAdapter = new MatchesAdapter(getDataSetMatches(), MatchesActivity.this);
    mRecyclerView.setAdapter(mMatchesAdapter);

    getUserMatchId();





}
 
Example 20
Source File: MoonPhasesView1.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs)
{
    initLocale(context);
    LayoutInflater.from(context).inflate(R.layout.layout_view_moonphases1, this, true);

    if (attrs != null)
    {
        LayoutParams lp = generateLayoutParams(attrs);
        centered = ((lp.gravity == Gravity.CENTER) || (lp.gravity == Gravity.CENTER_HORIZONTAL));
    }

    empty = (TextView)findViewById(R.id.txt_empty);
    card_view = (RecyclerView)findViewById(R.id.moonphases_card);

    card_layout = new LinearLayoutManager(context);
    card_layout.setOrientation(LinearLayoutManager.HORIZONTAL);

    card_view.setHasFixedSize(true);
    card_view.setItemViewCacheSize(7);
    card_view.setLayoutManager(card_layout);

    card_adapter = new PhaseAdapter(context);
    card_adapter.setItemWidth(Resources.getSystem().getDisplayMetrics().widthPixels / 4);  // initial width; reassigned later in onSizeChanged

    card_view.setAdapter(card_adapter);
    card_view.scrollToPosition(PhaseAdapter.CENTER_POSITION);

    GravitySnapHelper snapHelper = new GravitySnapHelper(Gravity.START); // new LinearSnapHelper();
    snapHelper.attachToRecyclerView(card_view);

    //card_scroller = new CardAdapter.CardViewScroller(context);
    //card_view.setOnScrollListener(onCardScrollListener);

    forwardButton = (ImageButton)findViewById(R.id.info_time_nextbtn);
    forwardButton.setOnClickListener(onResetClick1);
    forwardButton.setVisibility(GONE);

    backButton = (ImageButton)findViewById(R.id.info_time_prevbtn);
    backButton.setOnClickListener(onResetClick0);
    backButton.setVisibility(VISIBLE);
    backButton.postDelayed(new Runnable() {
        @Override
        public void run() {
            int position = card_layout.findFirstVisibleItemPosition();
            if (position == PhaseAdapter.CENTER_POSITION) {
                ViewUtils.fadeOutButton(backButton, ViewUtils.ANIM_VERYLONG);
            }
        }
    }, 1200);

    card_view.setOnScrollListener(onScrollChanged);

    initTheme(context);
    if (isInEditMode()) {
        updateViews(context);
    }
}