SlideLayout is a flexible and easy-to-use Android open source project that can help developers implement side-scrolling effects. What, you want to read README in English? Don’t wait two days.
use
gradle:
Step 1. Add the JitPack repository
allprojects {
repositories {
..
maven { url "https://jitpack.io"}}}Copy the code
Step 2. Add dependencies
dependencies {
compile 'Com. Making. Zpauly: SlideLayout: v1.0.0'
}Copy the code
maven
Step 1. Add the JitPack repository
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>Copy the code
Step 2. Add dependencies
<dependency>
<groupId>com.github.zpauly</groupId>
<artifactId>SlideLayout</artifactId>
<version< / a > v1.0.0version>
</dependency>Copy the code
2. Start using
1.xml
To start with, add the following content to your Layout file
<com.zpauly.swipeLayout.SlideLayout
android:id="@+id/slide_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<! --The lower layout-->
<include layout="@layout/behind_layout"/>
<! --The upper layout-->
<include layout="@layout/front_layout" />
</com.zpauly.swipeLayout.SlideLayout>Copy the code
Here the two child views in SlideLayout are the views that the user can slide. It is important to note that the position in the upper View code needs to be lower, and SlideLayout only slides the top View by default.
SlideLayout also provides properties that can be set directly in the layout file.
<com.zpauly.swipeLayout.SlideLayout
app:enableSlide="true"
app:enableSlideAuto="true"
app:ratioOfAutoSlideDirectionChange="0.5"
app:ratioOfBackToShow="1"
app:ratioOfResistance="0"
android:id="@+id/slide_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">... < /com.zpauly.swipeLayout.SlideLayout>Copy the code
The attribute name | Used to introduce |
---|---|
ratioOfResistance | Set slip resistance. The argument is a value of type float ranging from 0 to 1, where 0 means no drag and 1 means no sliding. The default is 0. |
ratioOfBackToShow | Set the area of a sliding child View that can expose the underlying View, that is, the sliding boundary of the child View. The argument is a float value in the range 0-1, representing the ratio of the range that can be slid to the area of the child View. The default value is 1. |
ratioOfAutoSlideDirectionChange | Set the position where the inertial slide direction will change after the drag operation, in conjunction with enableSlideAuto below. The argument is a float value in the range 0-1, representing the ratio of changing the position of the inertial slide to the range that the slippable sub-view can slide. Release when you drag the child View to reach this position and the child View will bounce back to its starting position, otherwise it will bounce back to the sliding boundary. |
enableSlide | Sets whether a child View in SlideLayout can slide. The parameter is a Boolean value. True indicates yes, false indicates no. The default is true. |
enableSlideAuto | Set whether inertial sliding is enabled. The parameter is a Boolean value, true meaning on, false meaning off. |
2.java
Then, if you have a SlideLayout object in your Activity or Fragment, here are the methods you can use.
methods | Used to introduce |
---|---|
void enableSlide(boolean enableSlide) | Same as enableSlide in the table above |
void enableSlideAuto(boolean enable) | Same as enableSlideAuto in the table above |
void setRatioOfResistance(float ratio) | Ratioofreid tag: 0 |
void setRatioOfBackToShow(float ratio) | Same as ratioOfBackToShow in table above |
void setRatioOfAutoSlideDirectionChange(float ratio) | With ratioOfAutoSlideDirectionChange in above table |
void setSlideDirection(SlideDirection direction) | Set the sliding direction. The parameter is an enumerated type, DIRECTION_LEFT(left), slidedirection_up (up), slidedirection_right (right), and slidedirection.di RECTION_DOWN (down) |
boolean isEnableSlide() | Gets the value of enableSlide |
boolean isEnableSlideAuto() | Gets the enableSlideAuto value |
float getRatioOfResistance() | Get the ratioofreid id value |
float getRatioOfBackToShow() | Get the value of ratioOfBackToShow |
float getRatioOfAutoSlideDirectionChange() | Obtain the ratioOfAutoSlideDirectionChange values |
SlideDirection getSlideDirection() | Gets the slippable direction |
void slideBack() | Slide the child View to its starting position |
void slideForward() | Causes the child View to slide automatically to the set slide boundary |
resetSlideView(int index) | Reset the sliding child View. The argument is a value of type int that represents the index of the child View in SlideLayout. |
boolean horizontalSmoothSlideTo(int left) | If the sliding direction is slidedirection_left or slidedirection_right, you can slide a child View within the sliding range to the specified position. |
boolean verticalSmoothSlideTo(int top) | If the sliding direction is slidedirection_up or slidedirection_down, you can slide a child View within the sliding range to the specified position. |
3.callback
A callback is also provided to listen for the slide.
public interface Callback {
void onSliding(View slideView.int left.int top.int dx.int dy);
void onSlideStateChanged(int newState);
}Copy the code
use
mSlideLayout.setCallback(new SlideLayout.Callback() {
@Override
public void onSliding(View slideView.int left.int top.int dx.int dy) {}@Override
public void onSlideStateChanged(int newState) {}});Copy the code
The last
Due to my limited level, if you have any comments or found any bugs, please feel free to issue or send me an email. I am here to express my thanks to you all.
Email address: [email protected]
Copyright 2016 zpauly
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copy the code