All Projects → Jawnnypoo → Physicslayout

Jawnnypoo / Physicslayout

Licence: apache-2.0
Android layout that simulates physics using JBox2D

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Physicslayout

FillProgressLayout
A simple and flexible Fillable Progress Layout written in Kotlin
Stars: ✭ 77 (-88.3%)
Mutual labels:  view, layout
Windfield
Physics module for LÖVE
Stars: ✭ 254 (-61.4%)
Mutual labels:  physics, box2d
table-layout
Styleable plain-text table generator. Useful for formatting console output.
Stars: ✭ 18 (-97.26%)
Mutual labels:  view, layout
pulldownlayout
PullDownLayout is a small library that allows you to implement a view that can be dragged down your layout. PullDownLayout can also be used to implement Pull-To-Dismiss feature for your activities and fragments.
Stars: ✭ 16 (-97.57%)
Mutual labels:  view, layout
Scalinglayout
With Scaling Layout scale your layout on user interaction.
Stars: ✭ 3,276 (+397.87%)
Mutual labels:  view, layout
ShadowDrawable
为View 和 ViewGroup 添加阴影效果--Android,Add shadow for single view or viewgroup layout.
Stars: ✭ 22 (-96.66%)
Mutual labels:  view, layout
FastBanner
🔥快速轮播图,支持自定义布局和使用自有图片显示组件
Stars: ✭ 27 (-95.9%)
Mutual labels:  view, layout
Expansionpanel
Android - Expansion panels contain creation flows and allow lightweight editing of an element.
Stars: ✭ 1,984 (+201.52%)
Mutual labels:  view, layout
Stevia
🍃 Concise Autolayout code
Stars: ✭ 3,182 (+383.59%)
Mutual labels:  view, layout
Stacks
⚡ Build React Native views blazingly fast.
Stars: ✭ 281 (-57.29%)
Mutual labels:  view, layout
Apple Music Animation
Apple music animation demo in Android
Stars: ✭ 153 (-76.75%)
Mutual labels:  physics, box2d
Mylinearlayout
MyLayout is a powerful iOS UI framework implemented by Objective-C. It integrates the functions with Android Layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,PathLayout,GridLayout,LayoutSizeClass to build your App 自动布局 UIView UITab…
Stars: ✭ 4,152 (+531%)
Mutual labels:  view, layout
Flexml
🚀基于Litho的Android高性能动态业务容器。
Stars: ✭ 225 (-65.81%)
Mutual labels:  view, layout
image-to-box2d-body
proof-of-concept game build pipeline for converting an image to a Box2D body
Stars: ✭ 24 (-96.35%)
Mutual labels:  physics, box2d
Android 3d Layout
Wow effect, transform your layout into 3D views
Stars: ✭ 199 (-69.76%)
Mutual labels:  view, layout
bubble-layout
An Android ViewGroup that displays avatar bubbles... similar to the chat bubbles on Facebook Messenger.
Stars: ✭ 46 (-93.01%)
Mutual labels:  view, layout
Arclayout
With Arc Layout explore new styles and approaches on material design
Stars: ✭ 1,662 (+152.58%)
Mutual labels:  view, layout
Android Statefullayout
A custom Android ViewGroup to display different states of screen (CONTENT, PROGRESS, OFFLINE, EMPTY, etc.)
Stars: ✭ 140 (-78.72%)
Mutual labels:  view, layout
Shapeofview
Give a custom shape to any android view, Material Design 2 ready
Stars: ✭ 2,977 (+352.43%)
Mutual labels:  view, layout
Bouncylayout
Make. It. Bounce.
Stars: ✭ 4,035 (+513.22%)
Mutual labels:  view, layout

PhysicsLayout

Build Status

Android layout that simulates physics using JBox2D. Simply add views, enable physics, and watch them fall!

See it in action with the sample app:

Google Play

Gradle Dependency

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Then, add the library to your project build.gradle

dependencies {
    implementation("com.github.Jawnnypoo:PhysicsLayout:latest.version.here")
}

Basic Usage

If you want to see what your layout looks like when physics is applied to it, simply change your root layout to a physics layout.

<com.jawnnypoo.physicslayout.PhysicsLinearLayout
  android:id="@+id/physics_layout"
  android:layout_width="match_parent"
  android:layout_height="200dp">
            
      <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"/>

      <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"/>
              
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello world, I have physics!"/>
            
</com.jawnnypoo.physicslayout.PhysicsLinearLayout>

Custom XML Attributes

You can also further customize the behaviour of your PhysicsLayout

<com.jawnnypoo.physicslayout.PhysicsLinearLayout
  android:id="@+id/physics_layout"
  android:layout_width="match_parent"
  android:layout_height="200dp"
  app:physics="true"
  app:gravityX="0.0"
  app:gravityY="9.8"
  app:bounds="true"
  app:boundsSize="50dp"/>
  • physics boolean, Determines if physics will be applied to the layout (Default true)
  • gravityX float, Sets the gravity in the X direction (positive is right, negative is left) (Default 0)
  • gravityY float, Sets the gravity in the Y direction (positive is down, negative is up) (Default 9.8)
  • bounds boolean, Determines if the layout should have bounds on the edges of itself (Default true)
  • boundsSize dimenstion, Sets the width/height of the bounds on the edges (Default 20dp)

Custom Physics Configuration

Each view contained within the layout has a physics configuration that it uses to create itself in the Box2D world. This defines its shape, mass, restitutaion, and other physics related variables. A custom configuration can be applied to each view as well:

<TextView
  android:id="@+id/text"
  android:layout_width="20dp"
  android:layout_height="20dp"
  app:layout_shape="circle"
  app:layout_circleRadius="20dp"
  app:layout_bodyType="kinematic"
  app:layout_fixedRotation="true"
  app:layout_friction="0.8"
  app:layout_restitution="0.3"
  app:layout_density="0.5" />

or alternatively, the Physics definition can be made programmatically:

val circleView = findViewById<View>(R.id.circle)
val config = PhysicsConfig(
    shape = Shape.CIRCLE,
    fixtureDef = fixtureDef,
    bodyDef = bodyDef
)
Physics.setPhysicsConfig(circleView, config)

This is useful especially if you have view that would be considered circular, as the default for all views is a RECTANGLE shape. Most of the time, if you are just dealing with rectangular views, the defaults will work for you and you will not have to worry about this.

Check out the sample app to see most of these things in action.

Making a Game?

This library was designed with the intention of allowing for playful animations within normal Android apps. It is not built to be a game engine or meant to compete with the likes. If you are looking to do more intense mobile games, we recommend libraries such as libGDX or Unity

License

Copyright 2020 John Carlson

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].