Android 当其中一个子视图在运行时代码中将其可见性更改为gone时,权重是否重新计算?

Android 当其中一个子视图在运行时代码中将其可见性更改为gone时,权重是否重新计算?,android,android-linearlayout,visibility,android-layout-weight,Android,Android Linearlayout,Visibility,Android Layout Weight,我有一个线性布局和两个线性布局作为孩子 他们有重量。有时,较低的linera布局子项的可见性消失了,但我希望较高的子项垂直居中 但事实并非如此 为什么呢 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical" android:backgroun

我有一个线性布局和两个线性布局作为孩子

他们有重量。有时,较低的linera布局子项的可见性
消失了
,但我希望较高的子项垂直居中

但事实并非如此

为什么呢

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:background="@color/google_blue900"
        android:orientation="vertical">
      <LinearLayout
          android:id="@+id/display_name_layout"
          android:layout_width="wrap_content"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:gravity="center_vertical"
          android:background="@color/google_red100"
          android:orientation="horizontal">
        <TextView
            android:id="@+id/account_display_name"
            style="@style/AccountDataDisplayName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/google_green50"
            tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
        <ImageView
            android:id="@+id/display_name_chevron"
            android:layout_width="@dimen/account_menu_chevron_size"
            android:layout_height="@dimen/account_menu_chevron_size"
            android:layout_marginTop="@dimen/account_menu_chevron_top_margin"
            android:layout_marginLeft="@dimen/account_menu_chevron_left_margin"/>
      </LinearLayout>
      <LinearLayout
          android:id="@+id/account_name_layout"
          android:layout_width="wrap_content"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:gravity="center_vertical"
          android:background="@color/google_blue50"
          android:orientation="horizontal">
        <TextView
            android:id="@+id/account_name"
            style="@style/AccountDataAccountName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:background="@color/google_yellow50"
            tools:text="emailisverylongaswellwewantittogettruncated@gmail.longdomain.com"/>
        <ImageView
            android:id="@+id/account_name_chevron"
            android:layout_width="@dimen/account_menu_chevron_size"
            android:layout_height="@dimen/account_menu_chevron_size"
            android:layout_marginTop="@dimen/account_menu_chevron_top_margin"
            android:layout_marginLeft="@dimen/account_menu_chevron_left_margin"/>
      </LinearLayout>
    </LinearLayout>

当我更改要消失的第二个线性布局的可见性时

我希望上面的线性布局在其线性布局父级中是中心垂直的

我遗漏了什么,因为现在它没有垂直居中


LL始终将it子项从左上角开始放置。 所以 当LL垂直时,对垂直中心没有意义
当LL horizontal

时,水平居中没有任何意义。它不是填充屏幕高度吗?@PankajKumar,正如您在屏幕截图中所看到的那样-蓝色是parten线性布局,因此上智利的高度没有跨度。但我不知道;我不在乎,我只是希望它垂直居中。在这种情况下,如果我理解你的问题,你需要对两种布局都使用安卓:layout_weight=“.5”。如果没有,请添加一个关于预期的草图