android ImageView 悬浮文字是怎么实现, 类似礼物说app.
PHP中文网
PHP中文网 2017-04-17 14:34:48
[Android讨论组]

PHP中文网
PHP中文网

认证0级讲师

全部回复(4)
高洛峰

感觉你给的图片,实现方式应该是FrameLayout,包含一个占满全部layout的ImageView,一个底部的TextView,一个右上角的用于显示数字的某种view。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="256dp"
    android:layout_margin="16dp"
    android:background="@android:color/background_dark" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY"
        android:src="@drawable/demo" />
    
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        android:textColor="@android:color/black"
        android:textSize="24sp"
        android:layout_gravity="bottom|center_horizontal" />

    <FrameLayout
        android:layout_gravity="end|top"
        android:layout_width="64dp" 
        android:layout_height="24dp"
        android:background="@android:color/background_light"
        android:alpha="0.5" >
        
        <ImageView
            android:layout_width="24dp"
            android:layout_height="match_parent"
            android:contentDescription="@string/app_name"
            android:scaleType="centerInside"
            android:src="@android:drawable/ic_menu_delete"
            android:layout_gravity="start|center_vertical" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="end|center_horizontal"
            android:gravity="end|center_vertical"
            android:text="1234"
            android:textColor="@android:color/black"
            android:textSize="14sp" />
        
    </FrameLayout>
    
</FrameLayout>

这份布局文件可以生成如下效果:

PS:
(1) 布局文件中的数字应该定义在res/values/dimens.xml中,此处只是为了方便。
(2) 这是我能想到的一种实现方式,应该还有更优的办法。

高洛峰

我能想到的最简单的实现方法
FrameLayout设置背景图片
FrameLayout里有个TextView显示文字
根本用不到ImageView吧。。。。。。

黄舟

用frameLayout和RelativeLayout都能实现啊

怪我咯

RecyclerView + cardview 然后在cardview里面TextView放置ImageView上面

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号