开发者

float animated ImageView on top of other elements within LinearLayout - android

开发者 https://www.devze.com 2023-01-12 18:16 出处:网络
I have an extended ImageView that I\'m reusing 7 times horizontally (within a LinearLayout) across my screen.Directly above and below this ImageView are other extended ImageViews that are within their

I have an extended ImageView that I'm reusing 7 times horizontally (within a LinearLayout) across my screen. Directly above and below this ImageView are other extended ImageViews that are within their own LinearLayouts. I'm spacing these all evenly by using the weight property within the LinearLayout so they space evenly across the screen. What I need to do is have this middle ImageView be able to float on top of either the top or bottom ImageViews to which it lines up with an animation. Is there some sort of z-index I can put on elements so that I can float this middle IV above the others?

Snippet of my 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开发者_如何学JAVA: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>

the ellipses just indicate that those imageviews are repeated 7 times each. Also, they are not TRUE ImageViews as I said, they are extended.

here is a snippet for the imageview that's in the middle (one with centerimage as its source) that does the animation (this is within the .java file)

    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);

}

some important considerations: I need to retain the even horizontal spacing for the 7 elements (all 3 rows of them). I'm open to using a different Layout type if my objectives can't be met with LinearLayout.

thanks for your time


I ended up writing a custom view and calling a stacked xml file with:

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

it seems to work and actually I like this solution better anyway because I'm including all three elements (in the 'column') into one view.

0

精彩评论

暂无评论...
验证码 换一张
取 消