Skip to content

支持在指定位置显示隐藏或者拖拽操作的轻量级的Android Library

Notifications You must be signed in to change notification settings

haikuowuya/HideShowDragView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

HideShowDragView - Alpha

A simple lightweight Android custom-view that supports a hide and show animation to a user specified position, as well as dragging. Alpha version - still under development.

Features:

  • Animation between two positions (hide / show)
  • Dragging and Dropping
  • Fully customizable

Usage

Simply copy the HideShowDragView.java file into your project.

Create a CustomView that extends HideShowDragView with the constructor you need

    public class CustomView extends HideShowDragView {
            
        public CustomView(Context context) {
            super(context);
        
            init();
        }
        
        public CustomView(Context context, AttributeSet attrs) {
            super(context, attrs);
        
            init();
        }
        
        private void init() {
            // e.g. inflate a layout
            addView(LayoutInflater.from(context).inflate(R.layout.custom_layout, null));
        }
        
        // ...
    }

Define your CustomView in .xml (supported container layouts are FrameLayout, RelativeLayout and LinearLayout)

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <your.package.CustomView
            android:id="@+id/customView"
            android:layout_width="90dp"
            android:layout_height="90dp" >
        </your.package.CustomView>
    </FrameLayout>

Initialize it from .xml (when defined in .xml):

    CustomView hideShowView = (CustomView) findViewById(R.id.customView);

Initialize a new CustomView:

    CustomView hideShowView = new CustomView(Context);

Inside your Activity or Fragment, use the HideShowDragListener to react to state changes and setup all parameters for your View:

    public class YourActivity extemds Activity implements HideShowDragListener {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.your_layout);
             
            // get the customview
            CustomView hideShowView = (CustomView) findViewById(R.id.customView);
            hideShowView.setHideShowListener(this);
            
            // alternative 1: set the position to which the view should animate from its current position
            hideShowView.setPosition(500, 500);
            // OR:
            // alternative 2: set the positions between the view should animate
            hideShowView.setPositions(0, 0, 500, 500);
            
            // setup other stuff ...
            hideShowView.makeInvisibleOnHide(false);
        
            hideShowView.setDragEnabled(true);
        }
        
        @Override
        public void onHide(HideShowDragView v, float curX, float curY) {

        }
  
        @Override
        public void onShow(HideShowDragView v, float curX, float curY) {

        }
    
        @Override
        public void onDragStart(HideShowDragView v, float startX, float startY) {
 
        }
    
        @Override
        public void onDragFinished(HideShowDragView v, float stopX, float stopY) {
        
        
        }
    }

About

支持在指定位置显示隐藏或者拖拽操作的轻量级的Android Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published