【安卓】让子元素超出容器限制、!如何实现更灵活的容器布局、!

安卓中LinearLayout是用得最得心应手的容器,但有时候貌似不尽人意,其实安卓中的容器真的很灵活。!

1.让子元素超出容器限制。初步想象一下,貌似子元素给定margin为负数即可超出,但事实却是超出容器部分没有绘制出来。

其实是可以绘制出来的,红色容器的容器(注意是红色控件的容器,不是红色容器自己)给定android:clipChildren="false"即可,该参数默认为true,即其内元素会被其容器裁剪,注意之所以是红色容器的容器,是因为绿色按钮突出部分已不在红色容器绘制范围内了,而属于红色容器的容器。

     


2.下面这种布局,按传统模式一般最外层用LinearLayout,里面再套RelativeLayout,以及各种恶心的排位。

其实可以来得更爽快一点,一个LinearLayout容器搞定。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:clipToPadding="false"
    android:orientation="horizontal"
    android:padding="10dp" >

    <TextView
        android:id="@+id/tvVIP"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="VIP1"
        android:textColor="#000000"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/et"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingRight="20dp"
        android:text="1000" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-20dp"
        android:text="元" />

    <Button
        android:id="@+id/btnDel"
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        android:layout_marginLeft="-15dp"
        android:layout_marginTop="-10dp" />

</LinearLayout>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值