GithubHelp home page GithubHelp logo

irmobydick / android-ratiolayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mapleqin/android-ratiolayout

0.0 1.0 0.0 10.97 MB

This is a specified proportion to the size of the Layout or View support library, with which you can easily set a fixed ratio of the size of the Layout or View, internal adaptive size calculation, completely abandon the code to calculate the size! If you have any questions in the course or suggestions, please send an e-mail to the following e-mail, thank you!

License: Apache License 2.0

Java 100.00%

android-ratiolayout's Introduction

Android-RatioLayout

This is a specified proportion to the size of the Layout or View support library, with which you can easily set a fixed ratio of the size of the Layout or View, internal adaptive size calculation, completely abandon the code to calculate the size! If you have any questions in the course or suggestions, please send an e-mail to the following e-mail, thank you!

For more information please see the website

Screenshots

Sample Sample

Android-RatioLayout with xml code

		<net.soulwolf.widget.ratiolayout.widget.RatioFrameLayout
			xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            soulwolf:datumRatio="datumWidth"
            soulwolf:widthRatio="16.0"
            soulwolf:heightRatio="9.0"
            android:layout_height="wrap_content">

            <net.soulwolf.widget.ratiolayout.widget.RatioImageView
                android:id="@+id/image2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                soulwolf:datumRatio="datumWidth"
                soulwolf:widthRatio="16.0"
                soulwolf:heightRatio="7.0"
                android:scaleType="centerCrop"/>

            <net.soulwolf.widget.ratiolayout.widget.RatioTextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textSize="25sp"
                android:textStyle="bold"
                android:gravity="center"
                soulwolf:datumRatio="datumWidth"
                soulwolf:widthRatio="16.0"
                android:background="@color/sample_text"
                soulwolf:heightRatio="7.0"
                android:text="RatioImageView/RatioTextView:16*7"
                android:textColor="@android:color/white"/>

        </net.soulwolf.widget.ratiolayout.widget.RatioFrameLayout>

		<net.soulwolf.widget.ratiolayout.widget.RatioRelativeLayout
			xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            soulwolf:datumRatio="datumWidth"
            soulwolf:widthRatio="15.0"
            android:layout_marginTop="8dp"
            soulwolf:heightRatio="10.0"
            android:layout_height="wrap_content"/>
		

Android-RatioLayout with java code

	RatioFrameLayout ratioFrameLayout = new RatioFrameLayout(context);
	ratioFrameLayout.setRatio(datumRatio,widthRatio,heightRatio);

Attr params info

attrName Explanation
datumRatio This parameter indicates the ratio is calculated based on Width Or Height!
widthRatio This parameter indicates the proportion of the size Width
heightRatio This parameter indicates the proportion of the size Height

Implementing View!

  • RatioAbsoluteLayout
  • RatioLinearLayout
  • RatioButton
  • RatioCheckBox
  • RatioCheckedTextView
  • RatioEditText
  • RatioFrameLayout
  • RatioGridLayout
  • RatioImageButton
  • RatioImageView
  • RatioProgressBar
  • RatioRadioButton
  • RatioRadioGroup
  • RatioRelativeLayout
  • RatioSpace
  • RatioTableLayout
  • RatioTextView

Custom

	public class RatioFrameLayout extends FrameLayout implements RatioMeasureDelegate {

    private RatioLayoutDelegate mRatioLayoutDelegate;

    public RatioFrameLayout(Context context) {
        super(context);
    }

    public RatioFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        mRatioLayoutDelegate = RatioLayoutDelegate.obtain(this, attrs);
    }

    public RatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mRatioLayoutDelegate = RatioLayoutDelegate.obtain(this, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public RatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mRatioLayoutDelegate = RatioLayoutDelegate.obtain(this, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if(mRatioLayoutDelegate != null){
            mRatioLayoutDelegate.onMeasure(widthMeasureSpec,heightMeasureSpec);
            widthMeasureSpec = mRatioLayoutDelegate.getWidthMeasureSpec();
            heightMeasureSpec = mRatioLayoutDelegate.getHeightMeasureSpec();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    public void setDelegateMeasuredDimension(int measuredWidth, int measuredHeight) {
        setMeasuredDimension(measuredWidth, measuredHeight);
    }

    @Override
    public void setRatio(RatioDatumMode mode, float datumWidth, float datumHeight) {
        if(mRatioLayoutDelegate != null){
            mRatioLayoutDelegate.setRatio(mode,datumWidth,datumHeight);
        }
    }

}

Maven

<dependency>
    <groupId>net.soulwolf.widget</groupId>
	<url>https://dl.bintray.com/soulwolf/maven</url>
    <artifactId>ratiolayout</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

allprojects {
   repositories {
      jcenter()
   }
}

compile 'net.soulwolf.widget:ratiolayout:1.0.0'

Developed by

Ching Soulwolf - [email protected]

License

Copyright 2015 Soulwolf Ching
Copyright 2015 The Android Open Source Project for Android-RatioLayout

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.

android-ratiolayout's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.