• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    Java
  • Created over 9 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[Deprecated] A Simple & Convenience MultiScreen-Support-Library for Android

Android-ScaleLayout

A Simple & Convenience MultiScreen-Support-Library for Android

The essence is percent scaling.

different from android-percent-support-lib

  1. More reliable
    android-percent-support-lib The percentage of the parent and child views.
    Android-ScaleLayout The percentage of the design and devices screens.

  2. More convenience
    android-percent-support-lib need to calculate percent.
    Android-ScaleLayout directly write the design size on layout.xml.

How to look?

screenhot

Principle

float realPixel = percent * designPixel

Pix Mode

float realPixel = percent * designPixel

float percent = mScreenWidth / designScreenWidth

float designPixel = res.getDimensionPixelSize()
float realPixel = mScreenWidth * res.getDimensionPixelSize() / designScreenWidth

DP Mode

float realPixel = percent * designPixel

float percent = mScreenWidth / designScreenWidth
float designPixel = designDP * designDensity // dp to pixel

float designDP = res.getDimensionPixelSize() / mDensity
float realPixel = (mScreenWidth * designDensity * getPixelSize()) / (designScreenWidth * mDensity)

Usage

0. dependencies

dependencies {
    compile 'cn.gavinliu.android.lib:ScaleLayout:1.0.4'
}

1. Initialize

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        ScaleConfig.create(this,
            1080, // Design Width
            1920, // Design Height
            3,    // Design Density
            3,    // Design FontScale
            ScaleConfig.DIMENS_UNIT_DP);
    }
}

TypedValue.COMPLEX_UNIT_SP is Android FontSize unit, the fontscale: float fontScale = ctx.getResources().getDisplayMetrics().scaledDensity;

2. Scale***Layout

Only need to replace FrameLayout LinearLayout RelativeLayout to ScaleFrameLayout ScaleLinearLayout ScaleRelativeLayout.

3. Scale by width or height

Width is default, you can also changed using attr.

<attr name="layout_scale_by" format="enum">
    <enum name="width" value="0"/>
    <enum name="height" value="1"/>
</attr>
app:layout_scale_by="width"

Support Attrs

<attr name="android:layout_width"/>
<attr name="android:layout_height"/>

<attr name="android:layout_margin"/>
<attr name="android:layout_marginLeft"/>
<attr name="android:layout_marginTop"/>
<attr name="android:layout_marginRight"/>
<attr name="android:layout_marginBottom"/>
<attr name="android:layout_marginStart"/>
<attr name="android:layout_marginEnd"/>

<attr name="android:padding"/>
<attr name="android:paddingLeft"/>
<attr name="android:paddingTop"/>
<attr name="android:paddingRight"/>
<attr name="android:paddingBottom"/>
<attr name="android:paddingStart"/>
<attr name="android:paddingEnd"/>

<!-- TextView -->
<attr name="android:textSize"/>

License

MIT

More Repositories

1

ShapedImageView

Android Rounded, Circle, Path ImageView
Java
332
star
2

NotificationBox

This is a tool app that solve too much notifications on android device
Java
197
star
3

SimpleOneStep

The SimpleOneStep is like OneStep about Smartisan OS 3.
Java
192
star
4

SimilarPhoto

Perceptual Hash Algorithm on Android
Java
102
star
5

Android-AbsListView-Drag-And-Drop

A complex ListView & GridView with Drag and Drop functionality
Java
44
star
6

Android-Pc-Socket-Connection

Android <---> PC , ADB Socket Connection Demo
Java
39
star
7

OpenGpad

Virtual Gamepad: Using the computer keyboard to play AndroidPhone Games
38
star
8

BeautifulOfBezier

Android Demo
Java
25
star
9

BeautifulOfRoundedBitmap

Android Demo
Java
20
star
10

OpenGpad-Android

Virtual Gamepad - Android Client
Java
11
star
11

SlidingFilterPanel

一个筛选功能的弹出框实现
Java
10
star
12

FloatingWindow

Easy to use floating window library in Android, just like fragment. Can help you build large floating window applications
Kotlin
10
star
13

BeautifulOfSin

Android Demo
Java
9
star
14

CustomQuickSettingTile

Android Demo
Java
7
star
15

glide-stackblur

Stackblur for glide
C
6
star
16

TransparentSystemBar

Android 4.4+ Transparent API
Java
5
star
17

AndroidStudio-ColorTheme-SublimeText2

Code color theme for AndroidStudio by Sublime Text 2
4
star
18

EatOreo

Android Oreo new api samples
Java
2
star
19

EventCast

EventCast for Android
Java
1
star
20

Android-Demos

Android Demo
Java
1
star
21

PDF.js4Android

PDF.js for Android
JavaScript
1
star
22

Cipher.File

This is encrypt & decrypt file tools based by AES
C
1
star
23

SpiderCover

xiami.com album cover spider base on scrapy
Python
1
star
24

Android-Drawables

BlurDrawale, CircleDrawale ...
C
1
star
25

termux-install-scripts

One key install scripts for termux
Shell
1
star
26

gavinliu.github.io

This is website source code for my blog.
HTML
1
star
27

Capsule

闪念胶囊
Java
1
star
28

A-tour-of-modern-Android-app-development

Shell
1
star
29

DropsPagerIndicator

Java
1
star