當前位置: 首頁>>代碼示例>>Java>>正文


Java RecyclerView.setLayoutManager方法代碼示例

本文整理匯總了Java中android.support.v7.widget.RecyclerView.setLayoutManager方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.setLayoutManager方法的具體用法?Java RecyclerView.setLayoutManager怎麽用?Java RecyclerView.setLayoutManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.RecyclerView的用法示例。


在下文中一共展示了RecyclerView.setLayoutManager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initView() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    mRvLayer = (RecyclerView) findViewById(R.id.rv_layer);
    mRvRoom = (RecyclerView) findViewById(R.id.rv_room);
    mSvRoom = (ObservableHorizontalScrollView) findViewById(R.id.sv_room);
    mRvLayer.setLayoutManager(new LinearLayoutManager(this));
    mRvLayer.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this)
            .color(Color.parseColor("#f5f5f5"))
            .size(1)
            .build()
    );
    mRvRoom.setLayoutManager(new LinearLayoutManager(this));
    mRvRoom.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this)
            .color(Color.parseColor("#f5f5f5"))
            .size(1)
            .build()
    );
}
 
開發者ID:GitLqr,項目名稱:TopsalesSellControlTableDemo,代碼行數:22,代碼來源:MainActivity.java

示例2: onCreate

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new GridLayoutManager(this, 1));

    adapter = new AppDataAdapter(this, getPackageManager(), new ArrayList<AppData>());
    recyclerView.setAdapter(adapter);

    new Thread() {
        @Override
        public void run() {
            PackageManager manager = getPackageManager();
            if (manager == null) return;

            final List<AppData> apps = new ArrayList<>();
            List<ResolveInfo> infos = manager.queryIntentActivities(new Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0);
            for (ResolveInfo info : infos) {
                apps.add(new AppData(info.loadLabel(manager).toString(), info.activityInfo.packageName));
            }

            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    adapter.setList(apps);
                }
            });
        }
    }.start();
}
 
開發者ID:TheAndroidMaster,項目名稱:PaletteGetter,代碼行數:33,代碼來源:MainActivity.java

示例3: initViews

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initViews() {

        list = (RecyclerView) findViewById(R.id.rmp_a_list);

        adapter = new RMPAdapter(this, data);
        list.setLayoutManager(new LinearLayoutManager(this));

        line = findViewById(R.id.rmp_a_line);
        title = (TextView) findViewById(R.id.rmp_a_title);
        toolbar = (Toolbar) findViewById(R.id.rmp_a_toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        first = new FirstThreeViewHolder(this, FirstThreeViewHolder.FIRST);
        second = new FirstThreeViewHolder(this, FirstThreeViewHolder.SECOND);
        third = new FirstThreeViewHolder(this, FirstThreeViewHolder.THIRD);
        first.setVisible(View.INVISIBLE);
        second.setVisible(View.INVISIBLE);
        third.setVisible(View.INVISIBLE);

    }
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:22,代碼來源:RecentMostPlayActivity.java

示例4: initView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initView() {
    mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
    mRefreshLayout.setEnabled(false);
    mLoadingLayout = (LoadingLayout) findViewById(R.id.loading_layout);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new RecyclerAdapter();
    mRecyclerView.setAdapter(mAdapter);

    mRetryBtn = (Button) findViewById(R.id.retry_btn);
    mEmptyBtn = (Button) findViewById(R.id.empty_btn);
    mCustomBtn1 = (Button) findViewById(R.id.custom1);
    mCustomBtn2 = (Button) findViewById(R.id.custom2);
    mRetryBtn.setOnClickListener(this);
    mEmptyBtn.setVisibility(View.GONE);
    mCustomBtn1.setVisibility(View.GONE);
    mCustomBtn2.setVisibility(View.GONE);
}
 
開發者ID:xiong-it,項目名稱:LoadingLayout,代碼行數:20,代碼來源:EmptyActivity.java

示例5: attachToRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void attachToRecyclerView(RecyclerView recyclerView)
{
    if (this.recyclerView == recyclerView)
    {
        return;
    }
    if (this.recyclerView != null)
    {
        destroyCallbacks();
    }
    this.recyclerView = recyclerView;
    if (recyclerView == null)
    {
        return;
    }
    onItemTouchListener = new TasksOnItemTouchListener(recyclerView.getContext());
    itemDecoration = new TasksItemDecoration();
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    recyclerView.addOnItemTouchListener(onItemTouchListener);
    recyclerView.addItemDecoration(itemDecoration);
    recyclerView.setAdapter(adapter);
    final Context context = this.recyclerView.getContext();
    final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    scaledTouchSlop = viewConfiguration.getScaledTouchSlop();
    DisplayMetrics metrics = new DisplayMetrics();
    final WindowManager systemService = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    systemService.getDefaultDisplay().getMetrics(metrics);
    logicalDensity = metrics.density;
    adapter.setOnFirstItemUpdateListener(new OnFirstItemUpdateListener());
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:31,代碼來源:TouchHelper.java

示例6: initRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initRecyclerView(RecyclerView recyclerView, int position) {
  recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
  mRecyclerViewAdapter = new RecyclerViewAdapter(getKanalSlugFraPosition(position));
  recyclerView.setAdapter(mRecyclerViewAdapter);

  //Remove focus from the RecyclerView so we can intercept the vertical scrolling events
  //recyclerView.setNestedScrollingEnabled(false);
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:9,代碼來源:MestSeteFrag.java

示例7: setUpViews

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
protected void setUpViews() {
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerViewNotes);
    //noinspection ConstantConditions
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    notesAdapter = new NotesAdapter(noteClickListener);
    recyclerView.setAdapter(notesAdapter);

    addNoteButton = findViewById(R.id.buttonAdd);

    editText = (EditText) findViewById(R.id.editTextNote);
    //noinspection ConstantConditions
    RxTextView.editorActions(editText).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<Integer>() {
                @Override
                public void call(Integer actionId) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {
                        addNote();
                    }
                }
            });
    RxTextView.afterTextChangeEvents(editText).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<TextViewAfterTextChangeEvent>() {
                @Override
                public void call(TextViewAfterTextChangeEvent textViewAfterTextChangeEvent) {
                    boolean enable = textViewAfterTextChangeEvent.editable().length() > 0;
                    addNoteButton.setEnabled(enable);
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:MainActivity.java

示例8: onCreate

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler);

    initData();

    mRecyclerView = (RecyclerView) findViewById(R.id.activity_recycler);
    adapter = new MyRecyclerAdapter(RecyclerActivity.this,mList);
    mRecyclerView.setAdapter(adapter);
    //設置線性布局
    mRecyclerView.setLayoutManager(new LinearLayoutManager(RecyclerActivity.this, LinearLayoutManager.VERTICAL, false));
}
 
開發者ID:Jmengfei,項目名稱:AddSubUtils,代碼行數:14,代碼來源:RecyclerActivity.java

示例9: onCreateView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    RecyclerView recyclerView = (RecyclerView) inflater.inflate(
            R.layout.recycler_view, container, false);
    ContentAdapter adapter = new ContentAdapter(recyclerView.getContext());
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return recyclerView;
}
 
開發者ID:sloiza,項目名稱:changApp,代碼行數:12,代碼來源:CardContentFragment.java

示例10: createHeadView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void createHeadView() {
    mHeadView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_video_hot_comment_head, mRecyclerView, false);
    RecyclerView recyclerView = (RecyclerView) mHeadView.findViewById(R.id.hot_comment_recycler);
    recyclerView.setHasFixedSize(false);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mVideoHotCommentAdapter = new VideoHotCommentAdapter(recyclerView, mHotComments);
    recyclerView.setAdapter(mVideoHotCommentAdapter);
    mAdapter.addHeaderView(recyclerView);
}
 
開發者ID:MUFCRyan,項目名稱:BilibiliClient,代碼行數:11,代碼來源:VideoCommentFragment.java

示例11: initRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initRecyclerView() {
    ScriptProjectAdapter adapter = new ScriptProjectAdapter(projectList, this);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.project_list);

    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);

    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(adapter);
}
 
開發者ID:Su-Yong,項目名稱:KakaoBot,代碼行數:12,代碼來源:MainActivity.java

示例12: onCreate

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTitle("線性排布");
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    textView1 = (TextView) findViewById(R.id.text1);
    textView2 = (TextView) findViewById(R.id.text2);
    textView3 = (TextView) findViewById(R.id.text3);
    textView4 = (TextView) findViewById(R.id.text4);
    helper = new SimpleHelper();
    SimpleHelperAdapter adapter = new SimpleHelperAdapter(helper);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new StickyHeaderDecoration(adapter));
    recyclerView.setAdapter(adapter);

    helper.notifyLoadingDataAndHeaderChanged(SimpleHelper.TYPE_FOUR, 3);
    textView3.postDelayed(new Runnable() {
        @Override
        public void run() {
            Random random = new Random();
            int rand = random.nextInt(6);
            List<MultiHeaderEntity> list = new ArrayList<>();
            for (int i = 0, size = rand + 1; i < size; i++) {
                list.add(new ThirdItem(String.format("我是第三種類型%d", i), 12 + i));
            }
            textView3.setText(String.format("類型3的數量:%d", list.size()));
            helper.notifyMoudleDataAndHeaderChanged(list, new HeaderThirdItem("我是第三種類型的頭", helper.getRandomId()), SimpleHelper.TYPE_FOUR);
        }
    }, 3000);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:LinearActivity.java

示例13: configRecycleView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * 配置recycleview
 *
 * @param recyclerView
 * @param layoutManager
 */
private void configRecycleView(RecyclerView recyclerView
        , RecyclerView.LayoutManager layoutManager
) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以確定每個item的高度是固定的,設置這個選項可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
 
開發者ID:snowwolf10285,項目名稱:PicShow-zhaipin,代碼行數:15,代碼來源:PhotosFragment.java

示例14: onCreate

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_edit);
    //設置ActionBar
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    if (mToolbar != null)
    {
        setSupportActionBar(mToolbar);
        setTitle(getText(R.string.activity_title_task_add));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    // 加載控件
    btnAction = (RelativeLayout) findViewById(R.id.rlyt_btnAction);
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    // 創建一個線性布局管理器
    mLayoutManager = new LinearLayoutManager(this);
    // layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    // 設置布局管理器
    mRecyclerView.setLayoutManager(mLayoutManager);
    // 裝填緩存數據
    app = (AppNaxy) this.getApplication();
    mData = new ModelTask();
    long unixTime = new Date().getTime();//獲取當前時區下日期時間對應的時間戳
    mData.setTimeCreate((int) (unixTime / 1000));
    mData.setTimeTarget(mData.getTimeCreate());
    mData.setTimeSort(mData.getTimeCreate());
    //讀取最後的使用色
    ToolSharedPreferences spfl = new ToolSharedPreferences(this, "set_info");
    mData.setColor(spfl.GetStringValue("color_last"));
    if (mData.getColor().length() <= 0)
    {
        mData.setColor("blue");
    }
    setColor(mData.getColor());
    initRecyclerView();
    //設置監聽
    btnAction.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            // 獲取輸入欄消息
            if (mData.getContent().length() > 0)
            {
                mData.setSub(mAdapter.DataSubGet());
                app.DBMGet().TaskAdd(mData);
                Intent i = new Intent();
                setResult(TYPE_ACTION_SUCCESS, i);
                ActivityTaskAdd.this.onBackPressed();
            }
        }
    });
}
 
開發者ID:kulics,項目名稱:xytodo-android,代碼行數:56,代碼來源:ActivityTaskAdd.java

示例15: onCreateView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_page, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recylerview);
    mFeedAdapter = new FeedAdapter("all");
    mRecyclerView.setAdapter(mFeedAdapter);



    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);

    return view;
}
 
開發者ID:mariabecker,項目名稱:OldNews,代碼行數:17,代碼來源:FeedFragment.java


注:本文中的android.support.v7.widget.RecyclerView.setLayoutManager方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。