رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

پست های پیشنهاد شده

کتابخانه ای که شما می توانید هر کدام از ایتم های موجود در لیست خود را بین دیگر آیتم ها جابجا کنید یا به عبارتی با درگ کردن آیتم مکان و position آنها را تغییر دهید

 

recyclerviewhelper

 

موارد زیر را در بخش dependency به پروژه خو اضافه کنید : 

// Required
implementation "com.android.support:appcompat-v7:{latest version}'
implementation "com.android.support:recyclerview-v7:{latest version}'

// RecyclerViewHelper
implementation 'com.github.nisrulz:recyclerviewhelper:{latest version}'

 

build.gradle
allprojects {
  repositories {
    google()
    jcenter()
  }
}

 

 

آداپتر مورد نظر برای لیست به صورت زیر ی باید:

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ItemViewHolder> implements RVHAdapter {
    
         ...
    
        @Override
        public boolean onItemMove(int fromPosition, int toPosition) {
            swap(fromPosition, toPosition);
            return false;
        }
    
        @Override
        public void onItemDismiss(int position, int direction) {
            remove(position);
        }
    
        public class ItemViewHolder extends RecyclerView.ViewHolder implements RVHViewHolder {
            ...
               
            @Override
            public void onItemSelected(int actionstate) {
                System.out.println("Item is selected");
            }
    
            @Override
            public void onItemClear() {
                System.out.println("Item is unselected");
    
            }
        }
    
        // Helper functions you might want to implement to make changes in the list as an event is fired
        private void remove(int position) {
            dataList.remove(position);
            notifyItemRemoved(position);
        }
    
        private void swap(int firstPosition, int secondPosition) {
            Collections.swap(dataList, firstPosition, secondPosition);
            notifyItemMoved(firstPosition, secondPosition);
        }
    }

 

 

public class MainActivity extends AppCompatActivity {
   
   
       RecyclerView myrecyclerview;
       ArrayList<String> data;
       MyAdapter adapter;
   
       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
   
           myrecyclerview = (RecyclerView) findViewById(R.id.rv_fruits);
   
           data = new ArrayList<>();
           data.add("Apple");
           ...
           data.add("Fig");
   
           // Setup your adapter
           adapter = new MyAdapter(data);
           // Setup 
           myrecyclerview.hasFixedSize();
           myrecyclerview.setLayoutManager(new LinearLayoutManager(this));
           myrecyclerview.setAdapter(adapter);
   
   
           // Setup onItemTouchHandler to enable drag and drop , swipe left or right
           ItemTouchHelper.Callback callback = new RVHItemTouchHelperCallback(adapter, true, true,
                   true);
           ItemTouchHelper helper = new ItemTouchHelper(callback);
           helper.attachToRecyclerView(myrecyclerview);
   
           // Set the divider in the recyclerview
           myrecyclerview.addItemDecoration(new RVHItemDividerDecoration(this, LinearLayoutManager.VERTICAL));
   
           // Set On Click Listener
           myrecyclerview.addOnItemTouchListener(new RVHItemClickListener(this, new RVHItemClickListener.OnItemClickListener() {
               @Override
               public void onItemClick(View view, int position) {
                   String value = "Clicked Item " + data.get(position) + " at " + position;
   
                   Log.d("TAG", value);
                   Toast.makeText(MainActivity.this, value, Toast.LENGTH_SHORT).show();
               }
           }));
   
       }
   }

 

 

 

پشتیبانی recyclerviewhelper

recyclerviewhelper-develop.zip

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

  • مطالب مشابه

    • توسط Omid Zakeri
      کتابخانه WindowImageView صفحه نمایش را به صورت یک background خاص نمایش می دهد همان طور که می بینید جلوه زیبا و حرفه ای به اپلیکیشن شما می دهد.
       

       
      ابتدا در قسمت build.gradle موارد زیر را اضافه کنید:
      repositories { maven { url "https://jitpack.io" } } dependencies { compile 'com.github.Bleoo:WindowImageView:1.0.2' }  
      در قسمت xml. 
      <io.github.bleoo.windowimageview.WindowImageView android:id="@+id/window_image_view" android:layout_width="match_parent" android:layout_height="180dp" app:frescoEnable="false" app:src="@drawable/timg" />  
      و در قسمت کلاس مربوط اکتیویتی قسمت زیر را اضافه کنید:
      window_image_view.setFrescoEnable(true); window_image_view.setImageResource(R.drawable.timg); window_image_view.bindRecyclerView(recyclerView);  

       
       
       
       
      راهنمایی و پشتیبانی : WindowImageView
       
      WindowImageView-master.zip
    • توسط Omid Zakeri
      MultiSnapRecyclerView کتابخانه ای با طراحی زیبا که به شما این امکان را می دهد لیست خود را به بهترین شکل و با طراحی فوق العاده طراحی کنید.
       

       
      ابتدا در قسمت Gradle مورد زیر را اضافه کنید:
      dependencies { implementation 'com.github.takusemba:multisnaprecyclerview:1.3.3' }  
      قسمت xml
      <com.takusemba.multisnaprecyclerview.MultiSnapRecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" app:msrv_gravity="start" or center, end app:msrv_ms_per_inch="@dimen/normal_speed" // speed of scrolling through. app:msrv_snap_count="2" /> items to scroll over  
       
      set  layout manager
      LinearLayoutManager layoutManager = new LinearLayoutManager(this); multiSnapRecyclerView.setLayoutManager(layoutManager); multiSnapRecyclerView.setAdapter(adapter); multiSnapRecyclerView.setOnSnapListener(new OnSnapListener() { @Override public void snapped(int position) { // do something with the position of the snapped view } });  
       
      راهنما و پشتیبانی : MultiSnapRecyclerView
       
       
       
       
       
       
      MultiSnapRecyclerView-master.zip
    • توسط Omid Zakeri
      با استفاده از این کتابخانه شما میتوانید  ckeckBox هایی دارای حالت انیمیشن را به برنامه خود اضافه کنید
       

       
       
      build.gradle
      repositories { // ... maven { url "https://jitpack.io" } }  
      dependency 
      dependencies { compile 'com.github.lguipeng:AnimCheckBox:1.0.1' }  
       
       
      **Maven**
      <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> <dependency> <groupId>com.github.lguipeng</groupId> <artifactId>AnimCheckBox</artifactId> <version>1.0.1</version> </dependency>  
       
      Layout File
      <com.github.lguipeng.library.animcheckbox.AnimCheckBox android:layout_gravity="center_horizontal" android:layout_width="80dp" android:padding="4dp" android:layout_height="wrap_content" app:stroke_width="4dp" app:stroke_color="#2196F3" app:circle_color="#1976D2" app:checked="true"/>  
       
       
      Java File
      AnimCheckBox checkbox = (AnimCheckBox)findViewById(R.id.checkbox) checkbox.setChecked(true); boolean animation = true; checkbox.setChecked(false, animation);  
       
       
      support AnimCheckBox
      AnimCheckBox-master.zip
    • توسط Omid Zakeri
      شما با استفاده از این کتابخانه زیبا و جذاب میتوانید لیست contact یا هر لیست دیگر را به صورت نمایه زیر نمایش دهید:
       

       
       
      حالا برای دانلود این کتابخانه قسمت زیر را در gradle اضافه کنید:
      dependencies { compile 'com.gjiazhe:wavesidebar:1.3' }  
       
      و در قسمت Layout میتوانید از این کتابخانه به صورت زیر استفاده کنید:
      <com.gjiazhe.wavesidebar.WaveSideBar android:id="@+id/side_bar" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingRight="8dp" app:sidebar_position="right" app:sidebar_max_offset="80dp" app:sidebar_lazy_respond="false" app:sidebar_text_color="#8D6E63" app:sidebar_text_size="14sp" app:sidebar_text_alignment="center"/>  
       
      سری ویژگی های این کتابخانه شامل موارد زیر است :
       

       
       
      شما می توانید از این ویژگی ها در قسمت layout یا در قسمت اکتیویتی استفاده کنید :
      WaveSideBar sideBar = (WaveSideBar) findViewById(R.id.side_bar); sideBar.setTextColor(Color.BLACK); sideBar.setMaxOffset(100); sideBar.setPosition(WaveSideBar.POSITION_LEFT); sideBar.setTextAlign(WaveSideBar.TEXT_ALIGN_CENTER); sideBar.setLazyRespond(true);  
       
      WaveSideBar sideBar = (WaveSideBar) findViewById(R.id.side_bar); sideBar.setOnSelectIndexItemListener(new WaveSideBar.OnSelectIndexItemListener() { @Override public void onSelectIndexItem(String index) { Log.d("WaveSideBar", index); // Do something here .... } });  
      شما با استفاده از متد setIndexItems می توانید برای Customize استفاده کنید.
       
      با استفاده از متد setPosition شما می توانید موقعیت قرار گیری آیتم هارا انتخاب کنید:
      sideBar.setPosition(WaveSideBar.POSITION_LEFT);
       
       
       
      پشتیبانی WaveSideBar
       
      WaveSideBar-master.zip
    • توسط Omid Zakeri
      این کتابخانه به منظور ارائه انیمیشن های جدید برای اکتیویتی ها در Android ایجاد شده است. با استفاده از کلاس ViewDragHelper، می توانید انیمیشن هایی  ایجاد کنید که امکان کنترل کامل نمایش را توسط کاربر فراهم می کند.
      Dragger در حال حاضر با استفاده از Rebound (کوچک، 41.7kb) از فیس بوک برای ارائه انیمیشن های واقع گرایانه و بهبود عملکرد دستگاه های قدیمی است.
      این کتابخانه باید بر روی API 10 کار کند.
       

       
       
      برای استفاده از این کتابخانه شما ابتدا موارد زیر را به build.gradle اضافه کنید:
      repositories { maven { url "https://jitpack.io" } } dependencies { compile 'com.github.ppamorim:dragger:1.2' }  
      سپس می توانید از این کتابخانه به صورت زیر استفاده کنید :
      <com.github.ppamorim.library.DraggerView android:layout_width="match_parent" android:layout_height="match_parent" dragger_layout:drag_view_id="@+id/drag_view" dragger_layout:shadow_view_id="@+id/shadow_view" dragger_layout:drag_position="top"> <FrameLayout android:id="@+id/shadow_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/transparent" android:visibility="invisible"/> <LinearLayout android:id="@+id/drag_view" android:layout_width="match_parent" android:layout_height="match_parent"/> </com.github.ppamorim.library.DraggerView>  
       
      قسمت styles:
      <style name="YourTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="android:windowAnimationStyle">@null</item> </style>  
       
      شما میتوانید در قسمت manifest اکتیویتی مربوطه را اضافه کنید :
      <activity android:name="com.github.dragger.BaseActivity" android:theme="@style/YourTheme"/>  
       
      یا از روش زیر میتوانید استفاده کنید:
      public class YourActivity extends DraggerActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setShadowView(R.layout.custom_shadow); // It is not necessary, use if you want. setContentView(R.layout.layout_content); } }  سری متد هایی که شما می توانید در این کاتبخانه استفاده کنید و به صورت Custom نمایش دهید:
      setDraggerCallback(DraggerCallback) //Interface that's provides some infos of the animation. setSlideEnabled(boolean) //Enable or disable the drag, useful to use with ScrollViews. setHorizontalDragRange(float) //Draggable distance that the draggableView can use, horizontally. setVerticalDragRange(float) //Draggable distance that the draggableView can use, vertically. setRunAnimationOnFinishInflate(boolean) //Run the initial animation, useful if you only want the drag function. setDraggerLimit(float) //Set the max limit drag, default is 0.5 (center of the screen). setDraggerPosition(DraggerPosition) //Set the position of archor. setTension(float) //Tension of the animation. This represent with the friction, how much time the animation will be executed. setFriction(float) //Friction of the animation. This represent with the tension, how much friction is applied at the tension animation. show() //Show the drag view with Rebound animation. closeActivity() //Simply close the activity with Rebound animation, based of the DraggerPosition choosen.  
       
       
       
      پشتیبانی:Dragger
       
      Dragger-master.zip
  • فایل

×
×
  • اضافه کردن...