RelativeLayout 和LinearLayout比较小tip

本文对比了RelativeLayout与LinearLayout在处理视图超出边界时的不同表现。RelativeLayout不允许子视图超出其边界,而LinearLayout则支持这一特性。通过具体的XML代码示例展示了两种布局方式的效果差异。

直接子view,RelativeLayout不支持超出RelativeLayout边界,LinearLayout支持

RelativeLayout 代码

<RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android"
   
android :layout_width="match_parent"
   
android :layout_height="match_parent"
   
android :weightSum="1">

    <
TextView
       
android :layout_width="555dp"
       
android :layout_height="1200dp"
       
android :text="New Text"
       
android :id="@+id/textView2"
       
/>

</RelativeLayout >

效果

113845_th4r_86964.png

LinearLayout 代码

<LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
   
android :layout_width="match_parent"
   
android :layout_height="match_parent"
   
android :weightSum="1"
   
android :orientation="vertical">

    <
TextView
       
android :layout_width="555dp"
       
android :layout_height="1200dp"
       
android :text="New Text"
       
android :id="@+id/textView2"
       
/>

</LinearLayout >


效果

113900_idMa_86964.png


转载于:https://my.oschina.net/lao4/blog/652612

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值