SelfAdjointView


Source link: https://github.com/CysionLiu/SelfAdjointView

SelfAdjointView

??????

SelfAdjointView is an Android library that allows developers to easily let view change with the parent which can scroll. The animation contains one or more of parallax,alpha,scale.

Apply to

  • ScrollView/HorizontalScrollView
  • ListView/GridView
  • RecyclerView
  • ViewPager
  • sth else that can scroll

EFFECT


.............


..............

Samples

click me

How do I use it?

Setup

dependencies {

// jCenter
compile 'com.cysion:adjointlib:1.3.0' 
}
 

Parallax

Now the effect can only use for image while the image can be places in any viewgroup provided it is AdjointImageView and it is wrapped by AdjointContainer. Note that in this condition, AdjointContainer should only have one child, and height/width of image should be larger than that of AdjointContainer(vertical move) and width/height of image should be larger than that of AdjointContainer(horizontal move).

lib provides VerticalMoveStyle and HoriMoveStyle..A new style can be created by implement AdStyle.

parameter type description
isVertical boolean AdjointImageView's config?can be defined in .xml?true is for vertical

Step 1

Code in layout

...<sth like scrollview>... <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#66ffffff"

android:orientation="horizontal"

android:padding="10dp">
  <com.cysion.adjointlib.view.AdjointContainer

android:id="@+id/container"

android:layout_width="180dp"

android:layout_height="100dp"

android:layout_gravity="center_horizontal"

android:layout_margin="10dp"

>

<com.cysion.adjointlib.view.AdjointImageView

 android:id="@+id/img_holder_img"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:adjustViewBounds="true"

 android:background="#99ff0000"

 android:padding="3dp"

 />
  </com.cysion.adjointlib.view.AdjointContainer>
  ...other view... </LinearLayout> ...</sth like scrollview>... 

Step 2

Set scroll View's location in Rect and provide a locator for AdjointContainer.

public class SecondActivity extends AppCompatActivity implements Locator{

 @Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

...
mContainer1 = (AdjointContainer) findViewById(R.id.adcontainer1);

mScrollView.post(new Runnable() {

 @Override

 public void run() {

  mScrollView.getGlobalVisibleRect(mR);

  mContainer1.setLocator(SecondActivity.this);

}

}
);
 .. 
}
  @Override
  public Rect getLocation() {

return mR;
  
}
  ... 
}
 

Step 3

create an obj of AdjointStyle and add it to the container.

 AdjointStyle style= new VerticalMoveStyle().minScale(0.9f);
  mContainer1.addStyle(style);

and now when parent scrolls, the image scrolls too.

Alpha/Scale

View(s) to show these effect should be wrapped in AdjointContainer.

From version 1.3.0 ,OnReachMiddleCallBack was provided for getting the middle item;

AdStyle' config:

parameter type description
minAlpha float minimum transprarency
minScale float minimum item size
linearable boolean method to caculate when scroll. True is for linear.
linearPos float position relative to scroll container(not AdjointContainer) when scale or alpha to be max.
factor float scale/factor factor
privotX float anchor of scale , x coordinate

Step 1

Code in layout

<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/scroller"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

 <com.cysion.adjointlib.view.AdjointContainer

 android:id="@+id/adcontainer1"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:layout_marginBottom="10dp">

  <com.cysion.adjointlib.view.AdjointImageView

  android:id="@+id/img_ad1"

  android:layout_width="match_parent"

  android:layout_height="wrap_content"

  android:adjustViewBounds="true"

  android:src="@mipmap/p1c"/>

  <TextView

  android:layout_width="wrap_content"

  android:layout_height="40dp"

  android:layout_alignParentBottom="true"

  android:layout_below="@+id/img_ad1"

  android:layout_centerHorizontal="true"

  android:text="Hello world"

  android:textColor="@color/colorPrimary"

  android:textSize="24sp"/>

</com.cysion.adjointlib.view.AdjointContainer>
....../other view.....
....../other view.....
....../other view.....
....../other view.....
  </LinearLayout>  </ScrollView>  

Step 2

Just like step2 in Parallex-step2.

Step 3

create one or more obj of AdjointStyle and add it to the container.

AdjointStyle style= new VerticalMoveStyle().minScale(0.9f);
 AdjointStyle style2= new VerticalAlphaStyle();
 ..  mContainer1.addStyle(style);
  mContainer1.addStyle(style2);
 ..

and now when parent scrolls, the image will change its alpha or scale.

Refer to sample app for more detail.

License

Copyright 2017 CysionLiu  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. 

Resources

AndroidPhotoFilters aims to provide fast, powerful and flexible image processing instrument for creating awesome effects on any image media.
Android choosing image from camera or gallery with Crop functionality
???? A basic sample android application to understand MVP in a very simple way. Just clone, build, run and understand MVP.
Pull or Swipe to Refresh Webview
Simple clock view for displaying uh...time?
Custom toasts with color and icon for Android.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes