在customView的ImageView上叠加许多Image View [英] Superpose many image View on an ImageView in a customView

查看:86
本文介绍了在customView的ImageView上叠加许多Image View的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这个ImageView上的ImageViewTextView组成的android中创建一个视图.但是我们可以在Android中创建的自定义视图包含的属性只能是某些类型,如本文所指定:定义自定义属性因此,我无法使用ImageView属性和TextView属性定义自定义视图. 我也不想这样定义它:

I would like to create a view in android that componsed of an ImageView and a TextView upon this ImageView. But the Custom views that we can create in Android contain attributes that can only be of certain types, as specified in this post : Defining custom attrs So I can't define a custom view with an ImageView attribute and a TextView attribute. I don't want to define it this way neither :

<FrameLayout android:id="@+id/frame_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

      <ImageView
         android:id="@+id/card_11"
         android:layout_width="@dimen/card_width"
         android:layout_height="@dimen/card_height"
         android:src="@drawable/carte_vierge_bleue"
         android:scaleType="fitXY"
         android:clickable="true" 
         android:visibility="visible"
         android:onClick="onCardClicked"/>

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1234 5678 1234 5678"
        android:layout_gravity="center"/>

</FrameLayout>

因为我想在此后的第一个ImageView上添加其他图像,所以我想拥有一个可以随意修改的自定义视图,并根据需要添加任意数量的ImageView,这种方式会使布局文件非常长... 有什么主意吗?

Because I would like to add other images on the first ImageView after that so I would like to have a custom view that I can modify however I want, and add on it as many ImageViews as I want, and this way of doing would make the layout file very long... Any idea ?

推荐答案

如果我正确理解,则可以将 RelativeLayout 与所需的ImageView一起使用. 例如:

If i understood correctly, you can use a RelativeLayout with as many ImageViews as you want. For example:

<RelativeLayout android:id="@+id/frame_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

      <ImageView
         android:id="@+id/card_11"
         android:layout_width="@dimen/card_width"
         android:layout_height="@dimen/card_height"
         android:src="@drawable/carte_vierge_bleue"
         android:scaleType="fitXY"
         android:clickable="true" 
         android:visibility="visible"
         android:onClick="onCardClicked"/>

     <ImageView
         android:id="@+id/card_12"
         android:layout_width="@dimen/card_width"
         android:layout_height="@dimen/card_height"
         android:src="@drawable/carte_vierge_bleue"
         android:scaleType="fitXY"
         android:clickable="true" 
         android:visibility="visible"
         android:onClick="onCardClicked"/>

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1234 5678 1234 5678"
        android:layout_gravity="center"/>

</RelativeLayout>

TextView将显示在 card12 ImageView 的顶部,而将显示在 card11 ImageView 的顶部,依此类推.

The TextView will be displayed on top of card12 ImageView, which will be displayed on top of card11 ImageView and so on.

希望它会有所帮助,Mattia

Hope it helped, Mattia

这篇关于在customView的ImageView上叠加许多Image View的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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