- 浏览: 550676 次
- 来自: -
博客专栏
-
libgdx 游戏开发
浏览量:11959
文章分类
- 全部博客 (171)
- OS (1)
- JavaScript (13)
- Struts (2)
- Regular Expression (1)
- Java (14)
- HTML (4)
- XML (1)
- Non-Relational Database (2)
- Miscellaneous (7)
- Lotus Notes (8)
- Algorithm (3)
- Web Analytics (6)
- Web (8)
- Perl (3)
- PHP (3)
- C & C++ (1)
- Shell (7)
- Google (1)
- Android (31)
- iPhone (1)
- SQL (1)
- HTML5 (3)
- jQuery (6)
- CSS (6)
- PostgreSQL (1)
- Design Patterns (1)
- Excel (1)
- Magento (4)
- jMeter (3)
- SEO (1)
- libgdx (5)
- Software (4)
- App (1)
- Game (1)
- Gradle (1)
- Linux (16)
- Ubuntu (4)
- Docker (2)
- Spring (2)
- Other (3)
- Directory Server (1)
- CentOS (1)
- Python (1)
- VCS (3)
- Database (1)
- Open Source (1)
最新评论
-
ls0609:
赞一个,支持下博主。
[原创] Android ListView 在右上角添加三角形图标和文字 -
love297:
不让别人商用,自己先商用起来了。
手机游戏开发展示 -
a851206:
你的有些类是哪里来的?我想研究一下你的程序,可是有些类没有代码 ...
[原创] Google Custom Search & Yahoo Boss Search | Web Search API 使用 -
ypppk:
BitmapFactory.Options options = ...
[原创] 连载 1 - 深入讨论 Android 关于高效显示图片的问题 - 如何高效的加载大位图 -
笑遍世界:
我也遇到了,弄清了其中原因,可参考我的博客:http://sm ...
[原创] 使用 jMeter 登录 Wordpress
最终显示效果如下图,在右上角添加三角形图标并在图标内显示文字:
注意:右上角的红色三角形和里面的文字不是图片。
原理是使用 Drawable 画出一个正方形,然后将其旋转 45 度,使其达到三角形的效果。
虽然可以直接使用 TextView 将其旋转 45 度,并添加背景 Drawable,但是这么做完之后我发现,如果想调整文字在三角形中的相对位置或者调整三角形的大小,却不是很容易。
因此我的方案是,使用 View 单独显示三角形背景,然后再使用 TextView 单独显示文字。这样做的好处就是可以随意的调整文字的相对位置以及三角形的大小。最终效果详见上图。
代码如下:在 drawable 文件夹下新建 triangle_shape.xml 文件,用以显示三角形图标。
在自己的 Layout 中,使用 triangle_shape.xml 作为背景,并添加三角形内需要显示的文字。
核心代码如下:
完整代码如下:
参考文献:
https://stackoverflow.com/a/32223301/6091500
注意:右上角的红色三角形和里面的文字不是图片。
原理是使用 Drawable 画出一个正方形,然后将其旋转 45 度,使其达到三角形的效果。
虽然可以直接使用 TextView 将其旋转 45 度,并添加背景 Drawable,但是这么做完之后我发现,如果想调整文字在三角形中的相对位置或者调整三角形的大小,却不是很容易。
因此我的方案是,使用 View 单独显示三角形背景,然后再使用 TextView 单独显示文字。这样做的好处就是可以随意的调整文字的相对位置以及三角形的大小。最终效果详见上图。
代码如下:在 drawable 文件夹下新建 triangle_shape.xml 文件,用以显示三角形图标。
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <rotate android:fromDegrees="-45" android:toDegrees="45" android:pivotX="0%" android:pivotY="-45%" > <shape android:shape="rectangle" > <!-- Border --> <stroke android:width="10dp" android:color="@color/red" /> <!-- Background --> <solid android:color="@color/red" /> </shape> </rotate> </item> </layer-list>
在自己的 Layout 中,使用 triangle_shape.xml 作为背景,并添加三角形内需要显示的文字。
核心代码如下:
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/thumbnail" android:layout_width="150dp" android:layout_height="85dp" fresco:placeholderImage="@drawable/placehoderImg" /> <FrameLayout android:id="@+id/onAirLayout" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignEnd="@+id/thumbnail" android:layout_alignParentTop="true" android:layout_alignRight="@+id/thumbnail"> <!-- Attention Please --> <!--layout_width must be equal to layout_height and its value plus layout_marginBottom must be equal 85--> <!--PS: 85 is the height of placeholder image--> <View android:layout_width="115dp" android:layout_height="115dp" android:layout_gravity="top|right|end" android:layout_marginBottom="-30dp" android:background="@drawable/triangle_shape" android:rotation="0" /> <TextView android:id="@+id/txtOnAir" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|end" android:layout_marginTop="12dp" android:rotation="45" android:text="@string/cmn_on_air" android:textColor="@android:color/white" android:textSize="14sp" /> </FrameLayout> </RelativeLayout>
完整代码如下:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fresco="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/swipe" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/thumbnail" android:layout_width="150dp" android:layout_height="85dp" fresco:placeholderImage="@drawable/placehoderImg" /> <FrameLayout android:id="@+id/onAirLayout" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignEnd="@+id/thumbnail" android:layout_alignParentTop="true" android:layout_alignRight="@+id/thumbnail"> <!-- Attention Please --> <!--layout_width must be equal to layout_height and its value plus layout_marginBottom must be equal 85--> <!--PS: 85 is the height of placeholder image--> <View android:layout_width="115dp" android:layout_height="115dp" android:layout_gravity="top|right|end" android:layout_marginBottom="-30dp" android:background="@drawable/triangle_shape" android:rotation="0" /> <TextView android:id="@+id/txtOnAir" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|end" android:layout_marginTop="12dp" android:rotation="45" android:text="@string/cmn_on_air" android:textColor="@android:color/white" android:textSize="14sp" /> </FrameLayout> </RelativeLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginLeft="8dp" android:layout_weight="1" android:gravity="center_vertical" android:orientation="vertical"> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginBottom="3dp" android:ellipsize="end" android:maxLines="1" android:text="Title" android:textAppearance="?attr/textAppearanceListItem" android:textColor="@android:color/black" android:textStyle="bold" /> <TextView android:id="@+id/subtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="-3dp" android:drawableLeft="@drawable/ic_place" android:drawablePadding="3dp" android:ellipsize="end" android:gravity="fill_vertical" android:maxLines="1" android:text="Sub Title" android:textColor="@color/dim_gray" android:textSize="12sp" /> </LinearLayout> </LinearLayout> </FrameLayout>
参考文献:
https://stackoverflow.com/a/32223301/6091500
发表评论
-
[转] DialogFragment Fragment already added
2017-10-25 11:16 2614原文地址:http://blog.csdn.net/u0129 ... -
Android Studio .gitignore
2017-10-16 15:44 837参考文献: https://github.com/github ... -
[转] How to detect incoming calls in an Android
2017-10-13 14:14 1170原文地址:https://stackoverflow.com/ ... -
[转] Android 检测电源按钮是否被按下
2017-10-11 12:55 959原文地址:https://stackoverflow.com/ ... -
[原创] Android Activity onNewIntent() 详解
2017-08-16 13:46 4719阅读难度:中 阅读前提: 1. 需要了解 Android 的生 ... -
[转] Android Webview: “Uncaught TypeError: Cannot read property 'getItem' of null
2017-08-14 15:09 2245原文地址:https://stackoverflow.com/ ... -
[原创] 使用 Vitamio 播放视频作为 Splash 时出现失真情况的解决方案
2017-08-02 09:10 1181目前在做关于视频及流媒体播放项目时,有这样一个需求,应用启动时 ... -
[转] Android: Expand/collapse animation
2017-07-31 14:57 1538原文地址:https://stackoverflow.com/ ... -
[转] Detect home button press in android
2017-07-20 17:49 1148原文地址:https://stackoverflow.com/ ... -
[原创] 开启 Android TextView Marquee
2017-07-18 15:47 1779亲测可能。直接上代码。 测试机器:XiaoMi 2S Andr ... -
[原创] 小米手机无法真机调试
2017-07-06 09:10 6452系统环境: 小米 2S MIUI 版本:8.0.1.0(LXA ... -
了解数据绑定 - Data Binding Library
2017-06-22 15:31 898原文地址: -
How to play gif with Fresco
2017-06-22 14:00 630原文地址:https://stackoverflow.com/ ... -
设置 Toolbar(ActionBar) 上的按钮颜色
2017-06-22 08:11 2036原文地址: https://stackoverflow.com ... -
Display back button on action bar and back event
2017-06-22 08:00 715原文地址: https://stackoverflow.com ... -
Gradle 修改 Maven 仓库地址
2017-06-02 15:51 1628修改 Gradle Maven 仓库地址为阿里云镜像 修改根 ... -
[转] How to clear cookies and cache of webview on Android when not in webview?
2017-04-26 09:28 2168原文地址:http://stackoverflow.com/a ... -
[转] Android 在程序中如何动态的修改程序图标
2017-03-02 17:05 884http://stackoverflow.com/a/4150 ... -
[转] Android Libraries
2017-01-16 10:28 539原文地址: https://dzone.com/article ... -
[原创] Android 长按识别图中二维码 - Zxing
2017-01-10 09:27 6325前提: 本文使用了 ButterKnife 依赖库 开始环境 ...
相关推荐
Android ListView边框圆角美化,可以用来仿iphone的个别界面。相当有用。美观。
android listview item 左右滑动删除
在实际开发中,很多项目都用到了,listView添加头部的写法,疫情我以为很难,最近偶然发现很简单,所以下了一个例子和大家交流
公司有个项目要用到类似手机QQ聊天记录列表ListView左右滑动后改变item的效果,网上没找到好的代码,偶然在安卓巴士的开源站http://d.apkbus.com/里面找到了SwipeToDismiss的源码...改成自己的显示另一个view的效果就行...
在listview 控件标题上添加图标的模块
android listview刷新 左右滑动
需求如题目:Android listview中item部分区域添加点击事件,在一个界面显示了listview,但显示的内容分为上下两部分,分别是白色的背景和蓝色的背景,现在需要只点击蓝色的背景,才能跳转到其他界面,解决方式如下:...
android ListView圆角显示的效果
http://blog.csdn.net/icqapp/article/details/24978057 详看效果图...android listview左右滑动分页(viewpager嵌套listview进行分页),焦点图带圆焦点 先敬告学者:如在此项目上运行不了的直接找到本人QQ:508181017,
Android实现带图标的ListView
android listview实现圆角。 有注释能看懂。
Android ListView每个Item上面的有TextView和Button,为ListView每个Item上面的按钮添加事件,并获取TextView文本信息。
android listview 左右滑动 实现 滑动删除
Android Listview Item上下拖动位置
Android ListView卡片效果,源码下载。
Android中listView的左右联动是非常常用的功能,最近我开发中就到了,所以写了一个例子,和大家交流学习。
Android 图标加文字ListView定制Demo,编辑器:Android Studio 3.1.2。
Android listview viewpager 滑动 跳动 冲突解决 ListView中嵌套ViewPage有或者滑动手势冲突解决 blog 地址 : http://blog.csdn.net/aaawqqq/article/details/43824631
android listView 改变选中行的 字体颜色和 图片
困扰了我好久,今天终于把它解决了。 需求是点击添加按钮,ListView增加一个Item,Item里面有一个按钮和一个EditText,点击按钮删除此item。