繁体   English   中英

如何将一堆线性布局转换为一个相对布局

[英]How do I convert a bunch of linear layouts to one relative layout

我一直在尝试学习如何在Android Studio中使用相对布局。 我只在布局中使用了一堆线性布局,而我看到的所有教程都展示了如何在右上角,中间,左下角等位置放置文本视图...但是我想知道如何可以将东西放置在任何位置,以将一堆线性布局转换为一个相对布局(例如:在父视图下放置1/3的东西)之类的东西,但是我没有运气来寻找有关的信息。 感谢任何帮助高级的人!

如果要使用RelativelayoutLinearlayout期货,则可以使用PercentRelativelayout这样

    <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.PercentFrameLayout>

你需要依赖

compile 'com.android.support:percent:24.1.1'

您希望通过LinearLayout实现的事情更多,因为它支持“ weight”属性。 相对而言,RelativeLayout顾名思义,使您可以相对于其他视图或父视图放置视图。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM