我的Android进阶之旅------>Android嵌入图像InsetDrawable的用法
面试题:为一个充满整个屏幕的LinearLayout布局指定背景图,是否可以让背景图不充满屏幕?请用代码描述实现过程。
解决此题,可以使用嵌入(Inset)图像资源来指定图像,然后像使用普通图像资源一样使用嵌入图像资源。
语法如下:
<?xml version="1.0" encoding="utf-8"?>
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:insetTop="dimension"
android:insetRight="dimension"
android:insetBottom="dimension"
android:insetLeft="dimension" />
元素解释:
android:insetTop:图像距离上边的距离。
android:insetRight:图像距离右侧的距离。
android:insetBottom:图像距离底边的距离。
android:insetLeft:图像距离左侧的距离。
下面使用具体的实例来看具体的效果
首先定义了一个嵌入图像资源,res/drawable/inset.xml
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/background"
android:insetBottom="50dp"
android:insetLeft="50dp"
android:insetRight="50dp"
android:insetTop="50dp" />
其中android:drawable="@drawable/background"引用的是drawable目录下的background.jpg文件,图像如下所示:
然后直接将inset.xml文件当做普通图像资源使用即可,代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/inset"><!-- 使用inset.xml作为背景图 --> <Button
android:id="@+id/buttonRingtone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置来电铃声" /> <Button
android:id="@+id/buttonAlarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置闹钟铃声" /> <Button
android:id="@+id/buttonNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置通知铃声" /> <EditText
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- 当前控件处于焦点状态 -->
<requestFocus />
</EditText>
</LinearLayout>
下面是具体的效果图,可以看到背景图没有占满全屏幕:
====================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
====================================================================================
我的Android进阶之旅------>Android嵌入图像InsetDrawable的用法的更多相关文章
- 我的Android进阶之旅------>Android颜色值(#AARRGGBB)透明度百分比和十六进制对应关系以及计算方法
我的Android进阶之旅-->Android颜色值(RGB)所支持的四种常见形式 透明度百分比和十六进制对应关系表格 透明度 十六进制 100% FF 99% FC 98% FA 97% F7 ...
- 我的Android进阶之旅------>Android中查看应用签名信息
一.查看自己的证书签名信息 如上一篇文章<我的Android进阶之旅------>Android中制作和查看自定义的Debug版本Android签名证书>地址:http://blog ...
- 我的Android进阶之旅------>Android利用温度传感器实现带动画效果的电子温度计
要想实现带动画效果的电子温度计,需要以下几个知识点: 1.温度传感器相关知识. 2.ScaleAnimation动画相关知识,来进行水印刻度的缩放效果. 3.android:layout_weight ...
- 我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(三)Android客户端功能实现
我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(一)PC服务器端(地址:http://blog.csdn.net/ouyang_pen ...
- 我的Android进阶之旅------> Android为TextView组件中显示的文本添加背景色
通过上一篇文章 我的Android进阶之旅------> Android在TextView中显示图片方法 (地址:http://blog.csdn.net/ouyang_peng/article ...
- 我的Android进阶之旅------> Android在TextView中显示图片方法
面试题:请说出Android SDK支持哪些方式显示富文本信息(不同颜色.大小.并包含图像的文本信息),并简要说明实现方法. 答案:Android SDK支持如下显示富文本信息的方式. 1.使用Tex ...
- 我的Android进阶之旅------>Android疯狂连连看游戏的实现之实现游戏逻辑(五)
在上一篇<我的Android进阶之旅------>Android疯狂连连看游戏的实现之加载界面图片和实现游戏Activity(四)>中提到的两个类: GameConf:负责管理游戏的 ...
- 我的Android进阶之旅------>Android疯狂连连看游戏的实现之加载界面图片和实现游戏Activity(四)
正如在<我的Android进阶之旅------>Android疯狂连连看游戏的实现之状态数据模型(三)>一文中看到的,在AbstractBoard的代码中,当程序需要创建N个Piec ...
- 我的Android进阶之旅------>Android疯狂连连看游戏的实现之状态数据模型(三)
对于游戏玩家而言,游戏界面上看到的"元素"千变万化:但是对于游戏开发者而言,游戏界面上的元素在底层都是一些数据,不同数据所绘制的图片有所差异而已.因此建立游戏的状态数据模型是实现游 ...
- 我的Android进阶之旅------>Android疯狂连连看游戏的实现之开发游戏界面(二)
连连看的游戏界面十分简单,大致可以分为两个区域: 游戏主界面区 控制按钮和数据显示区 1.开发界面布局 本程序使用一个RelativeLayout作为整体的界面布局元素,界面布局上面是一个自定义组件, ...
随机推荐
- Weblogic OutOfMemory exception的误解 -- thread limitation
不是全部的OutofMemory exception都是内存问题... 前几天有个客户的site报了下面错误: [ERROR][thread ] Could not start thread Time ...
- Android学习(十三) BroadcastReceiver组件(广播)
一.Broadcast(广播) 是一种广泛应用在应用程序之间传输信息的机制. 二.Broadcast(广播接收器) 是对发送出来的广播进行过滤接收并响应的一类组件,它就是用来接收来自系统和应用中的广播 ...
- Linux组件封装(四)使用RAII技术实现MutexLock自动化解锁
我们不止一次写过这种代码: { mutex_.lock(); //XXX if(....) return; //XXX mutex_.unlock(); } 显然,这段代码中我们忘记了解锁.那么如何防 ...
- LeetCode题目:Best Time to Buy and Sell Stock
原题地址:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ 解决方法:动态规划,minimun存储的是当前价格中最小的. c ...
- [转]Tomcat处理一个HTTP请求的过程
1.Tomcat Server的组成部分 1.1 - Server A Server element represents the entire Catalina servlet container. ...
- Maven 缺省内置变量
1.${project.build.directory} 构建目录,缺省为target 2.${project.build.outputDirectory} 构建过程输出目录,缺省为target/cl ...
- R 介绍
R定义:一个能够自由有效地用于统计计算和绘图的语言和环境,它提供了广泛的统计分析和绘图技术. R语言的使用很大程度上可以说是借助各种各种各样R包的辅助,从某种程度上说,运用R的插件来满足不同的需求. ...
- create table #temptable 临时表 和 declare @bianliang table ()表变量
create table #temptable 临时表 和 declare @bianliang table ()表变量 在开发过程中,经常会遇到使用表变量和本地临时表的情况.下面是对二者的一个介绍: ...
- 近期建了一个.net源代码共享群,群共享有大量网友分享的.net(C#)商业源代码
本群创建于2013/6/21: 群里都是.net(C#)程序开发者,群共享有大量网友分享的.net(C#)商业源代码.比方:DTCMS旗舰版,hishop微分销,shopnum微分销.多用户微信公众平 ...
- css写箭头
/* 向上的箭头 */ .dot-top { font-size: 0; line-height: 0; border-width: 10px; border-color: red; border-t ...