首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将ImageView放在ImageView Android之上

将ImageView放在ImageView Android之上
EN

Stack Overflow用户
提问于 2014-11-15 16:29:26
回答 2查看 1.7K关注 0票数 0

我看过这里的其他链接,但没有一条有效。我有一个LinearLayout (主容器是一个RelativeLayout),然后在LinearLayout中有一个ImageView和ImageView。我正在尝试在主ImageView内容之上放置一个play按钮。

下面是LinearLayout:

代码语言:javascript
复制
<LinearLayout android:orientation="horizontal" android:id="@+id/attach_previews_facebook" android:paddingLeft="64.0dip" android:layout_width="fill_parent" android:layout_height="150dip" android:layout_marginRight="8.0dip" android:layout_below="@id/attach_articles"> 
    <ImageView android:id="@+id/attach_preview_1" android:visibility="visible"
        android:layout_width="fill_parent" android:layout_height="match_parent"
        android:scaleType="center" 
        android:layout_weight="1"/>
    <ImageView android:id="@+id/videobtn" android:visibility="visible"
        android:layout_width="fill_parent" android:layout_height="match_parent"
        android:scaleType="center" 
        android:layout_weight="1"
        android:background="@drawable/play_button"/>        
</LinearLayout>

layout_weight除了在attach_preview_1旁边放置play按钮之外什么也不做(而不是在它的顶部)。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-15 16:41:16

看看FrameLayout。这个ViewGroup将所有的Views叠加在一起。

请参阅:http://developer.android.com/reference/android/widget/FrameLayout.html

备注:I强烈建议使用ImageButton或无边界按钮,而不是使用ImageView来完成此类任务。

更多信息:按钮ImageButton无边界

示例代码:

代码语言:javascript
复制
<FrameLayout
    android:id="@+id/attach_previews_facebook"
    android:layout_width="fill_parent"
    android:layout_height="150dip"
    android:layout_below="@id/attach_articles"
    android:layout_marginRight="8.0dip"
    android:paddingLeft="64.0dip" >

    <ImageView
        android:id="@+id/attach_preview_1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="center"
        android:visibility="visible" />

    <ImageView
        android:id="@+id/videobtn"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/play_button"
        android:scaleType="center"
        android:visibility="visible" />

</FrameLayout>
票数 2
EN

Stack Overflow用户

发布于 2014-11-15 16:44:47

您可以通过一个Layer ListFrameLayout来实现这一点:

图层列表法

res/drawable/layers.xml :

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
      <bitmap android:src="@drawable/android_red"
        android:gravity="center" />
    </item>
    <item android:top="10dp" android:left="10dp">
      <bitmap android:src="@drawable/android_green"
        android:gravity="center" />
    </item>
    <item android:top="20dp" android:left="20dp">
      <bitmap android:src="@drawable/android_blue"
        android:gravity="center" />
    </item>
</layer-list>

此布局XML将可绘制的XML应用于视图:

代码语言:javascript
复制
<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/layers" />

结果

FrameLayout方法

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:id="@+id/attach_previews_facebook" android:paddingLeft="64.0dip"
    android:layout_width="fill_parent" android:layout_height="150dip" android:layout_marginRight="8.0dip"
    >
    <ImageView android:id="@+id/attach_preview_1" android:visibility="visible"
        android:layout_width="fill_parent" android:layout_height="match_parent"
        android:scaleType="center"
        android:background="@drawable/iconevaleurs"
        android:layout_weight="1"/>

    <ImageView android:id="@+id/videobtn" android:visibility="visible"
        android:layout_width="127dp" android:layout_height="66dp"
        android:scaleType="center"
        android:layout_weight="1"
        android:background="@drawable/iconevaleurs"
        android:layout_gravity="center_horizontal|top" />
</FrameLayout>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26948003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档