Code Monkey home page Code Monkey logo

shrinklinearlayout's Introduction

ShrinkLinearLayout

ShrinkLinearLayout 是一个自定 LinearLayout,它的目的是当 LinearLayout 的子 View 高度超过 LinearLayout 的高度时,让子 View 按照一定的比例缩放

Demo

Download

Step 1. Add the JitPack repository to your build file

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

Step 2. Add the dependency

dependencies {
    implementation 'com.github.goyourfly:ShrinkLinearLayout:1.1'
}

Usage

一般和 LinearLayout 使用方法完全一致,但是多了一个 shrink 属性,通过 shrink 配置缩放强度,如果是 0 或者 froze,则不缩放

    <com.goyourfly.view.ShrinkLinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:background="#ddd"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="#673AB7"
            android:gravity="center"
            android:text="Shrink"
            android:textColor="@android:color/white"
            android:textSize="40dp"
            app:shrink="1" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:background="#9C27B0"
            android:gravity="center"
            android:src="@drawable/ic_launcher_foreground"
            android:text="A"
            android:textColor="@android:color/white"
            android:textSize="40dp"
            app:shrink="2" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:adjustViewBounds="true"
            android:background="#03A9F0"
            android:gravity="center"
            android:src="@drawable/ic_launcher_foreground"
            android:text="Froze"
            android:textColor="@android:color/white"
            app:shrink="frozen" />

    </com.goyourfly.view.ShrinkLinearLayout>

shrinklinearlayout's People

Contributors

goyourfly avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

shrinklinearlayout's Issues

高度计算错误问题修复记录

在 measure 时,为了修改 child 的高度,要通过修改 LayoutParams 的高度,但是每次 measure 的时候要先将 LayoutParams 恢复为初始状态,要不然计算就会错误,之前的做法是先获取所有子 View 的高度和,再恢复初始状态,在第一次 measure 时没啥问题,因为 LayoutParams 就是初始状态,但是如果再次触发 measure,这时获取 View 的高度和就是之前修改过的,导致计算错误,所以应该在 measure 最开始的地方恢复 LayoutParams 的状态
Fix measure bug

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.