2017-06-16 65 views
0

我利用线性布局,然后向布局添加权重以使布局屏幕独立。它解决了这个问题,但我被告知这种方法是不可取的?如何设计独立于屏幕的UI?

我该如何解决这个主要问题?

+0

https://developer.android.com/training/constraint-layout/index.html –

回答

0

你为什么不对PercentRelativeLayout

https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

它的RelativeLayout的一个小扩展中,你可以使用百分比宽度和高度 例如(从资料为准)

看看
<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%"/> 

现在,这将是在不同的屏幕不同雅叮叮屏幕宽度和高度

你也可以检查出蛇的评论如下。我想这更有前途

更新 作为@ cricket_007指出PercentRelativeLayout在API层面26.0.0-β1弃用。所以你应该真的使用ConstraintLayout,你仍然可以通过ConstraintLayout检查上面的链接来达到相同的结果。

+2

使用作为相对布局的“升级模型”的约束布局不是更好吗? – Snake

+1

是的,肯定约束布局是优化和扁平化的视图层次更好,但我还没有真正使用它,所以我不想给我的意见,直到我实现它,并看到你的表现为自己:) –

+0

你确实有一点关于百分比,因为相对父母似乎更容易。我将向社区发布一个关于比较 – Snake