【问题标题】:float animated ImageView on top of other elements within LinearLayout - android在 LinearLayout 中的其他元素之上浮动动画 ImageView - android
【发布时间】:2012-06-16 00:48:51
【问题描述】:

我有一个扩展的 ImageView,我在屏幕上水平重用了 7 次(在 LinearLayout 内)。在此 ImageView 的正上方和下方是其他扩展的 ImageView,它们位于它们自己的 LinearLayouts 中。我通过使用 LinearLayout 中的 weight 属性将它们均匀分布,以便它们在屏幕上均匀分布。我需要做的是让这个中间的 ImageView 能够漂浮在与动画对齐的顶部或底部 ImageView 的顶部。我可以在元素上放置某种 z-index 以便我可以将这个中间 IV 浮动在其他元素之上吗?

我的 xml 片段:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/opponentrow">
    <ImageView
        android:id="@+id/your1"
        android:layout_width="45px"
        android:layout_height="60px"
        android:src="@drawable/topimage"
        android:layout_weight="1" />
        ...
</LinearLayout>
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tokenrow">
    <ImageView
        android:id="@+id/your1"
        android:layout_width="20px"
        android:layout_height="20px"
        android:src="@drawable/centerimage"
        android:layout_weight="1" />
        ...             
</LinearLayout>
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/your1"
        android:layout_width="45px"
        android:layout_height="60px"
        android:src="@drawable/bottomimage"
        android:layout_weight="1" />
        ...
</LinearLayout>

省略号只是表示这些图像视图每个重复 7 次。此外,它们不是我所说的 TRUE ImageViews,它们是扩展的。

这是一个用于执行动画的中间图像视图的 sn-p(以 centerimage 作为其源)(在 .java 文件中)

    public Tokens(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        setOnClickListener(myListener);
    }

    private OnClickListener myListener = new OnClickListener(){
    public void onClick(View v) {
        doAnimate();
    }
}; 

private void doAnimate(){
    final Animation animUp = new TranslateAnimation(0,0,0,-22);
    animUp.setDuration(200);
    animUp.setFillAfter(true);

    final Animation animDown = new TranslateAnimation(0,0,0,22);
    animDown.setDuration(200);
    animDown.setFillAfter(true);
    if(avail)
        startAnimation(animDown);

}

一些重要的考虑:我需要为 7 个元素(所有 3 行)保持均匀的水平间距。如果 LinearLayout 无法满足我的目标,我愿意使用不同的 Layout 类型。

感谢您的宝贵时间

【问题讨论】:

    标签: android animation layout z-index android-linearlayout


    【解决方案1】:

    我最终编写了一个自定义视图并调用了一个堆叠的 xml 文件:

    View view=layoutInflater.inflate(R.layout.handlayout, this);
    

    它似乎有效,实际上我更喜欢这个解决方案,因为我将所有三个元素(在“列”中)包含在一个视图中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      相关资源
      最近更新 更多