【问题标题】:Android Linear Layout z-order animationAndroid 线性布局 z-order 动画
【发布时间】:2017-08-05 17:38:21
【问题描述】:

我在 LinearLayout 中有 3 个元素,我需要为其中一个设置动画。
动画开始时,该元素不在其他元素之上,而是在下方。
我已经尝试使用bringToFront(),但它不起作用(像文档说的那样更改顺序)。
我需要为这个“垂直”布局的“@id/ton”设置动画的元素。

<LinearLayout
    android:id="@+id/wrapInfo"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"   
    android:focusable="false"
    android:layout_gravity="center_horizontal"
    android:orientonion="vertical"
    android:clipChildren="false" >

    <ImageButton
        android:id="@+id/imageView1"
        android:layout_width="fill_parent" 
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginBottom="5dp"   
        android:background="@null"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/yourlogohere" /> 

   <TextView
       android:id="@+id/ton"
       android:layout_height="0dp"
       android:layout_weight="2"/>

    <WebView
        android:id="@+id/web"
        android:layout_width="match_parent" 
        android:layout_height="0dp"
        android:layout_weight = "1"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
         /> 

</LinearLayout>  

在这种情况下,TextView 位于 WebView 的下方。
我使用 LinearLayout 因为我需要这些元素是设备高度的 25/50/25%(我使用 weight xml 属性)。

【问题讨论】:

    标签: android android-animation android-linearlayout


    【解决方案1】:

    Z-Order 是 ViewGroup 子数组中的索引,如果要更改顺序,请使用 removeView() 然后 addView() 与新索引。

    在您的 LinearLayout 的情况下,如果添加了索引为 0 的视图,它将被放置在顶部,相反,如果添加了 index == viewGroup.getChildrenCount()-1 的视图,它将被放置在下方。

    稍后再致电viewGroup.requestLayout();

    【讨论】:

      猜你喜欢
      • 2014-12-24
      • 2017-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-03
      相关资源
      最近更新 更多