避免Android布局中的数字?

Msp*_*Msp 3 android android-layout

是否有可能设计出一个Android的布局(LinearLayoutRelativeLayout)不指定任何dp,px或任何其他单位?也许使用百分比?layout_weight是一个选择.但是利润率和填充量仍然如此?我们可以完全避免布局中的魔术数字吗?

Flo*_*ern 5

还有就是%的支持库,其PercentFrameLayoutPercentRelativeLayout在那里你可以指定任何布局尺寸(即大小,位置和边距)用百分比而不是绝对值:

<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>
Run Code Online (Sandbox Code Playgroud)