zoukankan      html  css  js  c++  java
  • RelativeLayout设置wrap_content无效

    尊重劳动成果,转载请标明出处:http://www.cnblogs.com/tangZH/p/8419053.html 

    在做项目的过程中,遇到了一个奇怪的现象,我设置RelativeLayout为的宽度为wrap_content,而且RelativeLayout里面的组件也设置了固定大小,可是RelativeLayout宽度大小还是会铺满整个屏幕。 

    为啥???一脸闷逼

    百度之后发现,官方文档有解释:

    A Layout where the positions of the children can be described in relation to each other or to the parent.Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM.

    它的意思大概是说:不能在RelativeLayout的大小和子级的位置之间存在循环依赖关系。 例如,不能将RelativeLayout的高度设置为WRAP_CONTENT,将子设置为ALIGN_PARENT_BOTTOM。

    就我遇到的两种情况而言是这样的:

    1、设置RelativeLayout的宽度为wrap_content,子组件设置为

    android:layout_alignParentEnd="true"

    于是出现了RelativeLayout宽度铺满屏幕的现象

    2、设置RelativeLayout的高度为wrap_content,子组件设置为

    ALIGN_PARENT_BOTTOM

    于是出现了RelativeLayout的高度铺满屏幕的现象

    最终,我还是乖乖改为LinearLayout布局

  • 相关阅读:
    排序算法整理
    V-REP Plugin 开发
    YAML-CPP
    YAML
    V-REP Remote API
    V-REP Plugin
    结构化方法与面向对象方法的比较
    敏捷软件开发vs传统软件工程
    个人项目-地铁出行路线规划程序
    Week1个人作业
  • 原文地址:https://www.cnblogs.com/tangZH/p/8419053.html
Copyright © 2011-2022 走看看