include属性选择

include标签内有一些属性,layout内也可以有一些属性
像<include layout="@layout/aa" />这种形式的include标签,layout内所有属性都有效。
但是如果想要用include内的属性,必须重新宽高,比如
    <include layout="@layout/aa"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
如果没有重写宽高,android:layout_alignParentRight="true"是无效的,但是写了宽高的话,layout内的layout属性都会失效(比如    android:layout_alignParentRight,android:layout_centerVertical都会失效),但是非layout属性依然有效比如gravity,background
简单说就说, include写了宽高,用include内的属性,layout内的layout相关属性失效
               include没写宽高,用layout内的属性



          


demo


activity_main.xml

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

    tools:context=".MainActivity">

    <include layout="@layout/aa" />
</RelativeLayout>
aa.xml
<?xml version="1.0" encoding="utf-8"?><!--完成按钮,带绿圆为背景的数字-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:gravity="right|center_vertical"
    android:orientation="horizontal">

    <TextView
        android:background="#ff0000"
        android:id="@+id/picker_image_preview_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:enabled="true"
        android:gravity="center"
        android:text="第一" />

    <TextView
        android:layout_marginLeft="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="你好" />

</LinearLayout>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值