android-percent-support-extend


Source link: https://github.com/hongyangAndroid/android-percent-support-extend

android-percent-support-extend

??android-percent-support?????

?????

  1. ?????????
  2. ??? PercentLinearLayout
  3. ????????????
  4. ??margin??????
  5. ??padding??????
  6. ??minWidth , maxWidth , minHeight , maxHeight??????
  7. ??TextView?Button?EditText?textSize
  8. ??ScrollView???Linearlayout
  9. ????View????????????

?????????????????????demo?github??

compile 'com.zhy:percent-support-extends:1.1.1'

? ?????

??????????????

  1. ?????????

  2. ??? PercentLinearLayout

  3. ???????????????????????

    ???

    app:layout_heightPercent="50%w" app:layout_marginPercent="15%w" app:layout_marginBottomPercent="20%h"
  4. ????app:layout_textSizePercent??textView?button,editText??textSize

    ???

     <TextView
    
     app:layout_textSizePercent="3%h"  />
  5. ?????ScrollView????????? PercentLinearLayout?????ScrollView????????????????android.R.id.content???(???????????????????????????View???????UNSPECIFIED)?

  6. ??minWidth,maxWidth,minHeight,maxHeight????

    ???

    app:layout_maxWidthPercent app:layout_maxHeightPercent app:layout_minWidthPercent app:layout_minWidthPercent

    ??????maxHeight????????????????maxHeight?????

  7. ??padding??????

    ???

    app:layout_paddingBottomPercent="8%w" app:layout_paddingLeftPercent="2%w" app:layout_paddingRightPercent="4%w" app:layout_paddingTopPercent="6%w"
  8. ???????????????

<ImageView
//...
 app:layout_heightPercent="30%sh"
 app:layout_widthPercent="30%sh"/>

? ?????????

???????????????????? PercentRelativeLayout? PercentFrameLayout?????????????????

layout_widthPercent? layout_heightPercent? layout_marginPercent? layout_marginLeftPercent? layout_marginTopPercent? layout_marginRightPercent? layout_marginBottomPercent? layout_marginStartPercent? layout_marginEndPercent?

???????????????????????????????????????????????????????????????????????????

  1. ????????????????

    ??????????200*100?????????????????20%?10%?????????????????????20%???????????10%??????????

  2. ?????????????????

    ??????????????? FloatingActionButton?????????????????10%??????

  3. ?????margin???????

    ????????margin?????????????????????5%???????????5%?????????5%?

????????????????percent-support-lib????????????????????????????????????????????????????????????2???????????10%w?10%w????????????????????????????

? ??

Android Studio

???????????????android studio???????

dependencies {

  //...
  compile 'com.zhy:percent-support-extends:1.0.7' 
}
 

????????percent-support-lib??

??????????

com.zhy.android.percent.support.PercentLinearLayout com.zhy.android.percent.support.PercentRelativeLayout com.zhy.android.percent.support.PercentFrameLayout

###????? :

  • layout_heightPercent
  • layout_widthPercent
  • layout_marginBottomPercent
  • layout_marginEndPercent
  • layout_marginLeftPercent
  • layout_marginPercent
  • layout_marginRightPercent
  • layout_marginStartPercent
  • layout_marginTopPercent
  • layout_textSizePercent
  • layout_maxWidthPercent
  • layout_maxHeightPercent
  • layout_minWidthPercent
  • layout_minHeightPercent
  • layout_paddingPercent
  • layout_paddingTopPercent
  • layout_paddingBottomPercent
  • layout_paddingLeftPercent
  • layout_paddingRightPercent

???????10%w , 10%h , 10% , 10%sw , 10%sh

? ?????

Demo 1 [?????????w,h??]

xml:

<?xml version="1.0" encoding="utf-8"?>
<com.zhy.android.percent.support.PercentFrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

<com.zhy.android.percent.support.PercentFrameLayout

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="center"

android:background="#ff44aacc"

app:layout_heightPercent="50%w"

app:layout_widthPercent="50%w">

 <com.zhy.android.percent.support.PercentFrameLayout

 android:layout_width="0dp"

 android:layout_height="0dp"

 android:layout_gravity="center"

 android:background="#ffcc5ec7"

 app:layout_heightPercent="50%w"

 app:layout_widthPercent="50%w">

  <TextView

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:layout_gravity="center"

  android:background="#ff7ecc16"

  android:gravity="center"

  android:text="margin 15% of w"

  app:layout_marginPercent="15%w"

  />

 </com.zhy.android.percent.support.PercentFrameLayout>

</com.zhy.android.percent.support.PercentFrameLayout>

<TextView android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="bottom|right"

android:background="#44ff0000"

android:gravity="center"

android:text="15%w,15%w"

app:layout_heightPercent="15%w"

app:layout_marginPercent="5%w"

app:layout_widthPercent="15%w"/>
</com.zhy.android.percent.support.PercentFrameLayout> 

Demo 2 [?????????w,h??]

xml:

<?xml version="1.0" encoding="utf-8"?> <com.zhy.android.percent.support.PercentFrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<TextView

android:id="@+id/id_test"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="left|top"

android:background="#44ff0000"

android:gravity="center"

android:onClick="test1"

android:text="width:30%,height:20%"

app:layout_heightPercent="20%"

app:layout_widthPercent="30%"/>

<TextView

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="right|top"

android:background="#4400ff00"

android:gravity="center"

android:text="width:70%,height:20%"

app:layout_heightPercent="20%"

app:layout_widthPercent="70%"/>

 <TextView

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="bottom"

android:background="#770000ff"

android:gravity="center"

android:text="width:100%,height:10%"

app:layout_heightPercent="10%"

app:layout_widthPercent="100%"/>

 <ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:scaleType="centerCrop"

android:src="@drawable/tangyan"

app:layout_heightPercent="50%h"

app:layout_widthPercent="50%w"/>

<TextView

android:layout_width="0dp"

android:layout_height="0dp"

app:layout_heightPercent="10%h"

app:layout_widthPercent="10%h"

android:text="10%h,10%h"

android:gravity="center"

android:layout_gravity="bottom|right"

android:background="#44ff0000"

app:layout_marginBottomPercent="20%h"

app:layout_marginRightPercent="10%"/>
</com.zhy.android.percent.support.PercentFrameLayout>

ok?????????????????????????????????????????????????????????????????????????????????????


????????????????TextView??textSize???????????ScrollView??????????ScrollView????????????????????????? PercentLinearLayout?ScrollView???????????? UNSPECIFIED???????????????????????View??????????????????View?????????????????????????????????????????android.R.id.content??????????ScrollView????10%h???????????????????ActionBar?????

Demo 3 [??textSize?ScrollView]

xml:

<?xml version="1.0" encoding="utf-8"?>  <ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <com.zhy.android.percent.support.PercentLinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

 <TextView

 android:layout_width="0dp"

 android:layout_height="0dp"

 android:background="#ff44aacc"

 android:gravity="center"

 android:text="width:60%,height:5%,ts:3%"

 android:textColor="#ffffff"

 app:layout_heightPercent="5%"

 app:layout_marginBottomPercent="5%"

 app:layout_textSizePercent="3%"

 app:layout_widthPercent="60%"/>

 <TextView

 android:layout_width="0dp"

 android:layout_height="0dp"

 android:background="#ff4400cc"

 android:gravity="center"

 android:text="width:70%,height:10%"

 android:textColor="#ffffff"

 app:layout_heightPercent="10%"

 app:layout_marginBottomPercent="5%"

 app:layout_widthPercent="70%"/>

<TextView

 android:layout_width="0dp"

 android:layout_height="0dp"

 android:background="#ff44aacc"

 android:gravity="center"

 android:text="w:80%,h:15%,textSize:5%"

 android:textColor="#ffffff"

 app:layout_heightPercent="15%"

 app:layout_marginBottomPercent="5%"

 app:layout_textSizePercent="5%"

 app:layout_widthPercent="80%"/>

<TextView

 android:layout_width="0dp"

 android:layout_height="0dp"

 android:background="#ff4400cc"

 android:gravity="center"

 android:text="width:90%,height:5%"

 android:textColor="#ffffff"

 app:layout_heightPercent="20%"

 app:layout_marginBottomPercent="5%"

 app:layout_widthPercent="90%"/>

 <TextView

 android:layout_width="match_parent"

 android:layout_height="0dp"

 android:background="#ff44aacc"

 android:gravity="center"

 android:text="width:100%,height:25%"

 android:textColor="#ffffff"

 app:layout_heightPercent="25%"

 app:layout_marginBottomPercent="5%"

 />

 <TextView

 android:layout_width="match_parent"

 android:layout_height="0dp"

 android:background="#ff44aacc"

 android:gravity="center"

 android:text="width:100%,height:30%"

 android:textColor="#ffffff"

 app:layout_heightPercent="30%"

 app:layout_marginBottomPercent="5%"

 />

 </com.zhy.android.percent.support.PercentLinearLayout> </ScrollView>  

??????TextView????????5%?????????????PercentLinearLayout?ScrollView??ok~ ??????????????????????????????????????????????

Demo 4 [?????????????]

thx for Sunday~

<?xml version="1.0" encoding="utf-8"?> <com.zhy.android.percent.support.PercentFrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<TextView

android:id="@+id/id_test"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="left|top"

android:background="#44ff0000"

android:gravity="center"

android:onClick="test1"

android:text="width:30%sw,height:20%sh"

app:layout_heightPercent="20%sh"

app:layout_widthPercent="30%sw"/>

<TextView

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="right|top"

android:background="#4400ff00"

android:gravity="center"

android:text="width:70%sw,height:20%sh"

app:layout_heightPercent="20%sh"

app:layout_widthPercent="70%sw"/>

 <TextView

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_gravity="bottom"

android:background="#770000ff"

android:gravity="center"

android:text="width:100%,height:10%sw"

app:layout_heightPercent="10%sw"

app:layout_widthPercent="100%"/>

 <ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:scaleType="centerCrop"

android:src="@drawable/tangyan"

app:layout_heightPercent="30%sh"

app:layout_widthPercent="30%sh"/>

<TextView

android:layout_width="0dp"

android:layout_height="0dp"

app:layout_heightPercent="10%sh"

app:layout_widthPercent="10%sh"

android:text="10%sh,10%sh"

android:gravity="center"

android:layout_gravity="bottom|right"

android:background="#44ff0000"

app:layout_marginBottomPercent="15%sw"

app:layout_marginRightPercent="10%sw"/>
</com.zhy.android.percent.support.PercentFrameLayout> 

About me


==> ??????????

Android Percent Support Lib Sample 📐📐📐

I made a sample of the new percent support library.
It will be documented soon on android dev website so it's just a proof of concept :)
You can check official docs reference here

This library provide percentage based layouts, horizontal and vertical at the same time.

simple result

complex result


from https://gist.github.com/shekarshine/5458f697c02e5619b0e2

How to use :

just add percent support library to your project

dependencies {

  compile 'com.android.support:percent:22.2.0' 
}

###Supported Layouts :

####PercentRelativeLayout

<android.support.percent.PercentRelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

 <View

android:id="@+id/top_left"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_alignParentTop="true"

android:background="#ff44aacc"

app:layout_heightPercent="20%"

app:layout_widthPercent="70%" />

<View

android:id="@+id/top_right"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_alignParentTop="true"

android:layout_toRightOf="@+id/top_left"

android:background="#ffe40000"

app:layout_heightPercent="20%"

app:layout_widthPercent="30%" />

 <View

android:id="@+id/bottom"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_below="@+id/top_left"

android:background="#ff00ff22"

app:layout_heightPercent="80%" /> </android.support.percent.PercentRelativeLayout>

####PercentFrameLayout

<android.support.percent.PercentFrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<!-- ... XML CODE --> </android.support.percent.PercentFrameLayout>

###Stylable :

  • heightPercent
  • widthPercent
  • marginBottomPercent
  • marginEndPercent
  • marginLeftPercent
  • marginPercent
  • marginRightPercent
  • marginStartPercent
  • marginTopPercent

Pre-requisites

  • Android SDK v22
  • Android Build Tools v22.0.1
  • Android Percent Support Repository v22.2.0
  • Android Support v4 Repository v22.2.0

according to the the manifest minsdk is v7 (android 2.1)

####License Mit

Resources

JGiven is a developer-friendly and pragmatic BDD tool for Java. Developers write scenarios in plain Java using a fluent, domain-specific API, JGiven generates reports that are readable by domain experts.

Android social login (facebook, google, etc) helper powered by RxJava.

Codegeneration tool for isomorphic server and mobile Go apps backed by gRPC & Protobuf. Share code between your backend, Android & iOS app!

This is a Web Viewer component.

Tint and colorize Android views easily.

Library allows to cache Observables during orientation change. It's useful during HTTP request, which must be performed only once. After onComplete, Observables are automatically removed from cache.

ObservableCacheService is additional layer over ObservableCache, which generate classes with access to Observables in cache.

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