使用Android提供的支持库-Percent Support Library,可以让我们使用百分比来制作ui界面,更加方便我们适配。
官方链接: https://developer.android.com/topic/libraries/support-library/features.html#recommendation
目前仅支持PercentFrameLayout和PercentRelativeLayout两种布局,git上有别人写的关于LinearLayout的扩展。
具体使用: :
<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">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentRelativeLayout>
其他属性有:
最好自己看源码,实现其他ViewGroup的实现! 共勉!!