简体   繁体   English

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

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

I have been trying to learn how to use relative layouts in Android Studios. 我一直在尝试学习如何在Android Studio中使用相对布局。 I have only made layouts with a bunch of linear layouts inside of them and all of the tutorials I have seen display how to put a text view in the top right corner, center, bottom left etc...but I want to know how I can place things in any location to convert a bunch of linear layouts to one relative layout(example: Place something 1/3 down the parent view) and things like that but I have had no luck finding information on that. 我只在布局中使用了一堆线性布局,而我看到的所有教程都展示了如何在右上角,中间,左下角等位置放置文本视图...但是我想知道如何可以将东西放置在任何位置,以将一堆线性布局转换为一个相对布局(例如:在父视图下放置1/3的东西)之类的东西,但是我没有运气来寻找有关的信息。 Thanks to anyone who helps in advanced! 感谢任何帮助高级的人!

If you want to use Relativelayout and Linearlayout futures you can use PercentRelativelayout like this 如果要使用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>

you need dependency of it 你需要依赖

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

The thing which you want to achieve is more possible from LinearLayout, as it supports "weight" property. 您希望通过LinearLayout实现的事情更多,因为它支持“ weight”属性。 RelativeLayout on the other side, as the name suggests lets you to place your views in relation to other views or parent. 相对而言,RelativeLayout顾名思义,使您可以相对于其他视图或父视图放置视图。

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

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