堆叠图像视图重叠 [英] Stacking image views with overlapping

查看:134
本文介绍了堆叠图像视图重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想叠彼此相邻图像视图(含70%重叠)。我用的FrameLayout,并给出了10各elemnet填充它的工作,但是当涉及到​​处理该事件填充是我的命。是否有重叠的观点(使用不同的layout..etc)中没有更好的办法?我开发的Andr​​oid 2.3

I am trying to stack image views beside each other (with 70% overlapping). I used a frameLayout and gave each elemnet padding of 10. It worked but this padding is killing me when it comes to handling events. Is there any better way of overlapping views (use different layout..etc)? I am developing for Android 2.3

   <RelativeLayout android:layout_height="fill_parent"  
android:layout_width="fill_parent" >

    <FrameLayout     
    android:id="@+id/frameLayoutBottom"      
    android:layout_width="wrap_content"      
    android:layout_height="wrap_content"     
    android:layout_alignParentBottom="true"      
    android:layout_centerHorizontal="true" > 
    <ImageView          
    android:id="@+id/ivBottom1"          
    android:layout_width="wrap_content"          
    android:layout_height="wrap_content"          
    android:src="@drawable/c10" />      
    <ImageView      
    android:id="@+id/ivBottom2"          
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"                        
    android:paddingLeft="10dp"          
    android:src="@drawable/c11" /> 

顺便说一句,当我尝试保证金,而不是填充,图像仍然对海誓山盟100%顶级

By the way, when I try the margin instead of padding, the images are still on top of eachother 100%

推荐答案

创建一个自定义的ViewGroup,规定了它的孩子onLayout。有相当多的例子,如果你搜索定制的ViewGroup onLayout。在一般情况下,onLayout方法重写看起来是这样的:

Create a custom ViewGroup that lays out it's children in onLayout. There are quite a few examples if you search for "custom ViewGroup onLayout". In general, the onLayout method override looks like this:

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {}

在该方法中,你将要使用getChildCount()和getChildAt(指数),以获得引用您的孩子的意见。一旦你有他们,你可以用L,T,R和B值来比较你的ViewGroup的界限,并找出其中布局的孩子们。

Inside that method, you will want to use getChildCount() and getChildAt(index) to get references to your child views. Once you have them, you can use the l,t,r, and b values to compare the bounds of your ViewGroup and figure out where to layout the children.

一旦你找到了孩子,并计算出您想要的地方,你会使用child.layout(L,T,R,B)把孩子查看新的自定义的ViewGroup里。

Once you find the children and calculate where you want them, you'll use child.layout(l,t,r,b) to place the child view inside your new custom ViewGroup.

希望这有助于。如果你真的需要破解这一转换成XML,你可以尝试以下方法:

Hope this helps. if you REALLY need to hack this into XML, you can try the following :

<RelativeLayout    
android:layout_width="fill_parent"      
android:layout_height="fill_parent"> 
<ImageView 
android:id="@+id/spacer1"         
android:layout_width="10dp"          
android:layout_height="wrap_content" />         
<ImageView       
android:layout_width="wrap_content"
android:layout_height="wrap_content"         
android:src="@drawable/whatever1" /> 
<ImageView       
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_toRightOf="id/spacer1"        
android:src="@drawable/whatever2" /> 
</RelativeLayout>

这篇关于堆叠图像视图重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆