inflate引入的布局高度不对问题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:gravity="center_vertical"
    android:layout_height="@dimen/ios_public_space_90px"
    android:orientation="horizontal" >
    <View
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="1px"
        android:layout_marginRight="@dimen/ios_public_space_40px"
        android:background="@color/pub_color_eighteen" />


    <TextView
        android:layout_gravity="center"
        android:layout_weight="0"
        android:layout_width="wrap_content"
        android:gravity="center"
        android:text="android"
        android:textColor="@color/pub_color_eighteen"
        android:textSize="@dimen/ios_public_textsize_24pt" />


    <View
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="1px"
        android:layout_marginLeft="@dimen/ios_public_space_40px"
        android:background="@color/pub_color_eighteen" />

</LinearLayout>

引入这个布局后,我们会发现view绘制出来后高度与预期的是不一样的,并没有想象中的90px,如果想让整个view高度达到90px,可以在textview中加上android:layout_height="@dimen/ios_public_space_90px",因为最外层的的高度即使设置了也是wrap_content的,需要在内层布局中重新确认高度。

在此在说一句,有时我们想要隐藏引入的布局,但是setVisibility(View.GONE)却没有效果,我们可以在嵌套一层布局,给内层的布局设置GONE,这样就能成功隐藏了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值