Android使用shape使组件呈现出特殊效果的方法

本文实例讲述了Android使用shape使组件呈现出特殊效果的方法。分享给大家供大家参考,具体如下:

使用到的布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:background="#ffffff"
  android:gravity="center_horizontal">
  <TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="未使用效果"
    android:layout_marginTop="30dp"
    />
  <EditText
    android:id="@+id/edit"
    android:layout_width="280dp"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="未使用效果 未使用效果 未使用效果 未使用效果 未使用效果 未使用效果"
    android:cursorVisible="true"
     />
  <TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="使用效果"
    android:layout_marginTop="10dp"
    />
  <EditText
    android:id="@+id/edit2"
    android:layout_width="280dp"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="使用效果 使用效果 使用效果 使用效果 使用效果 使用效果 使用效果 使用效果"
    android:background="@drawable/shape"
    android:cursorVisible="true"
     />
</LinearLayout>

使用到的shape文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
  <corners
    android:radius="10dp"
    />
  <gradient
    android:startColor="#33CC00"
    android:endColor="#666600"
    android:angle="45"
    />
  <padding
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp"
    />
  <stroke
    android:width="3dp"
    android:color="#FF3300"
    />
</shape>

在这里主要说一下shape文件中各项的功能

gradient主要设置背景颜色渐变。startColor为起始颜色值,endColor为结束颜色值,angle为渐变角度
padding主要设置组件里内容距离组件内边框的间距
stroke主要设置组件的边框。width为边框宽度,color为边框颜色

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android布局layout技巧总结》、《Android视图View技巧总结》、《Android编程之activity操作技巧总结》、《Android操作json格式数据技巧总结》、《Android资源操作技巧汇总》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。

(0)

相关推荐

  • Android shape和selector 结合使用实例代码

    shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和selector在美化控件中的作用是至关重要的. 1.Shape 简介 作用:XML中定义的几何形状 位置:res/drawable/文件的名称.xml 使用的方法: Java代码中:R.drawable.文件的名称 XML中:android:background="@drawable/文件的名称&

  • Android开发之WebView组件的使用解析

    在 Android 手机中内置了一款高性能 webkit 内核浏览器, SDK 中封装为一个叫做 WebView 组件. WebView 类是 WebKit 模块 Java 层的视图类,( 所有需要使用 Web 浏览功能的Android应用程序都要创建该视图对象显示和处理请求的网络资源.目前,WebKit 模块支持 HTTP.HTTPS.FTP 以及 javascript 请求. WebView 作为应用程序的 UI 接口,为用户提供了一系 列的网页浏览.用户交互接口,客户程序通过这些接口访问

  • Android Shape控件美化实现代码

    如果你对Android系统自带的UI控件感觉不够满意,可以尝试下自定义控件,我们就以Button为例,很早以前Android123就写到过Android Button按钮控件美化方法里面提到了xml的selector构造.当然除了使用drawable这样的图片外今天Android开发网谈下自定义图形shape的方法,对于Button控件Android上支持以下几种属性shape.gradient.stroke.corners等.  我们就以目前系统的Button的selector为例说下: <s

  • Android中shape定义控件的使用

    Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码: <shape> <!-- 实心 --> <solid android:color="#ff9d77"/> <!-- 渐变 --> <gradient android:startColor="#ff8c00" android:endColor="#FFFFFF

  • Android开发教程之shape和selector的结合使用

    shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和selector在美化控件中的作用是至关重要的. 1.Shape 简介 作用:XML中定义的几何形状 位置:res/drawable/文件的名称.xml 使用的方法: Java代码中:R.drawable.文件的名称 XML中:android:background="@drawable/文件的名称&

  • Android编程使用自定义shape实现shadow阴影效果的方法

    本文实例讲述了Android编程使用自定义shape实现shadow阴影效果的方法.分享给大家供大家参考,具体如下: 直接上xml文件, 并且附上相应的解析: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_p

  • Android控件系列之Shape使用方法

    如果你对Android系统自带的UI控件感觉不够满意,可以尝试下自定义控件,我们就以Button为例,很早以前Android123就写到过Android Button按钮控件美化方法里面提到了xml的selector构造.当然除了使用drawable这样的图片外今天Android开发网谈下自定义图形shape的方法,对于Button控件Android上支持以下几种属性shape.gradient.stroke.corners等. 复制代码 代码如下: 我们就以目前系统的Button的select

  • Android中的Shape和Selector的结合使用实例

    一:在Android程序开发中,我们经常会去用到Shape这个东西去定义各种各样的形状,首先我们了解一下Shape下面有哪些标签,都代表什么意思: (1).solid:填充 android:color指定填充的颜色 (2).gradient:渐变 android:startColor和android:endColor分别为起始和结束颜色, android:angle是渐变角度,必须为45的整数倍. 另外渐变默认的模式为android:type="linear",即线性渐变, 可以指定渐

  • Android Selector和Shape的使用方法

    1.背景选择器(位于res/drawable/,使用方法:android:background="@drawable/XXX") 复制代码 代码如下: <?xml version="1.0" encoding="utf-8"?> <selectorxmlns:android="http://schemas.android.com/apk/res/android"> <itemandroid:dra

  • Android自定义shape的使用示例

    MainActivity如下: 复制代码 代码如下: package cn.testshape; import android.os.Bundle; import android.app.Activity; /** * Demo描述: * 自定义shape的使用 */ public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.o

  • 三款Android炫酷Loading动画组件推荐

    最近突然心血来潮,对一些Loading感兴趣,Loading这玩意说重要也重要,说不重要也不重要,因为这是一个提升你产品体验的一个细节,如果loading做的好,对于一些耗时需要用户等待的页面来说会转移用户注意力,不会显得那么烦躁,所以你可以看到市面上各种各样好玩的Loading动画,那么这篇博客就准备收集下一些Loading动画吧,从这些实现思路上可以打开你们自己的思维,没准也会有创新好玩的Loading动画出现. 暂且先列举些最近GitHub新鲜出炉的Loading CircleProgre

  • Android中drawable使用Shape资源

    本文实例为大家分享了drawable使用Shape资源的具体内容,供大家参考,具体内容如下 1.画一条水平方向的虚线 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke andro

随机推荐