android代码shape
① android 里用shape画圆,怎么填充颜色
Android里面使用shape设置控件的外形,例如一些圆角、填充的背景颜色、以及一些渐变的效果等,所以设置填充颜色,可通过设置shape.xml文件里的如下属性:
1
<solid android:color="@color/common_red" />
将shape文件放到android的button、textview组件上,就可以有填充背景颜色的效果,完整的代码如下:
1.shape.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false" >
<solid android:color="@color/common_red" />
<padding
android:left="2dp"
android:top="1dp"
android:right="2dp"
android:bottom="1dp" />
<solid
android:color="@color/common_red" />
<stroke
android:width="1dp"
android:color="@android:color/white" />
<size android:width="15dp"
android:height="15dp" />
2011年医师资格考试合格标准 356
2010年医师资格考试合格标准 351
2009年医师资格考试合格标准 345
2008年医师资格考试合格标准 359
医师资格证书是国内行医必不可少的"通行证",科目医师资格考试是评价申请医师资格者是否具备从事医师工作所必须通过的考试。
2014乡执业助理医师成绩已公布,乡镇执业助理医师成绩也同时公布,国家医学考试中心查。
乡镇执业助理医师分数线需等各省公布各省的。会在这段时间之内全部公布请耐心等待!
② android shape solid 如何在代码中设置
在XML文件里设置,然后在需要的控件上用background属性引用
比如:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#ffda7585" /> <!-- 内容颜色 -->
<stroke android:width="1.0dip" android:color="#50cccccc" /> <!-- 边框大小、颜色-->
<corners android:radius="10.0dip" /> <!-- 圆角弧度 -->
</shape>
</item>
</selector>
③ 安卓在代码中设置Textview的shape,怎么设置
res目录下面创建一个文件夹drawable,里面创建一个xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="3dp"/>
<stroke android:width="0.7dp"
android:color="#000000" />
<!--下面为背景填充色,需要跟上面的进行区别 -->
<solid android:color="#ffffff"/>
</shape>
④ android 中既要设置shape 又要设置selector 怎么办
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/文件的名称"
属性:
<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"]
其中rectagle矩形,oval椭圆,line水平直线,ring环形
<shape>中子节点的常用属性:
<gradient> 渐变
Android:startColor 起始颜色
Android:endColor 结束颜色
Android:angle 渐变角度,0从上到下,90表示从左到右,数值为45的整数倍默认为0;
Android:type 渐变的样式 liner线性渐变 radial环形渐变 sweep
<solid > 填充
Android:color 填充的颜色
<stroke > 描边
Android:width 描边的宽度
Android:color 描边的颜色
Android:dashWidth 表示'-'横线的宽度
Android:dashGap 表示'-'横线之间的距离
<corners > 圆角
Android:radius 圆角的半径 值越大角越圆
Android:topRightRadius 右上圆角半径
Android:bottomLeftRadius 右下圆角角半径
Android:topLeftRadius 左上圆角半径
Android:bottomRightRadius 左下圆角半径
2.Selector
简介
位置:res/drawable/文件的名称.xml
使用的方法:
Java代码中:R.drawable.文件的名称
XML中:Android:background="@drawable/文件的名称"
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片-->
<item Android:drawable="@drawable/pic1" />
<!-- 没有焦点时的背景图片 -->
<item
Android:state_window_focused="false"
android:drawable="@drawable/pic_blue"
/>
<!-- 非触摸模式下获得焦点并单击时的背景图片 -->
<item
Android:state_focused="true"
android:state_pressed="true"
android:drawable= "@drawable/pic_red"
/>
<!-- 触摸模式下单击时的背景图片-->
<item
Android:state_focused="false"
Android:state_pressed="true"
Android:drawable="@drawable/pic_pink"
/>
<!--选中时的图片背景-->
<item
Android:state_selected="true"
android:drawable="@drawable/pic_orange"
/>
<!--获得焦点时的图片背景-->
<item
Android:state_focused="true"
Android:drawable="@drawable/pic_green"
/>
</selector>
第一个例子:圆角的Button
第二个例子:shape+selector综合使用的例子 漂亮的ListView
selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<item Android:state_selected="true">
<shape>
<gradient Android:angle="270" android:endColor="#99BD4C"
android:startColor="#A5D245" />
<size Android:height="60dp" android:width="320dp" />
<corners android:radius="8dp" />
</shape>
</item>
<item Android:state_pressed="true">
<shape>
<gradient Android:angle="270" android:endColor="#99BD4C"
android:startColor="#A5D245"/>
<size Android:height="60dp" android:width="320dp" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape>
<gradient Android:angle="270" android:endColor="#A8C3B0"
android:startColor="#C6CFCE" />
<size Android:height="60dp" android:width="320dp" />
<corners android:radius="8dp" />
</shape>
</item>
</selector>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
Android:layout_width="fill_parent"
android:layout_height="wrap_content"
Android:background="@drawable/selector"
>
<ImageView
Android:id="@+id/img"
Android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
/>
<TextView
Android:text="data"
android:id="@+id/title"
Android:layout_width="fill_parent"
android:layout_height="wrap_content"
Android:gravity="center_vertical"
android:layout_marginLeft="20dp"
Android:layout_marginTop="20dp"
android:textSize="14sp"
Android:textStyle="bold"
android:textColor="@color/black"
>
</TextView>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
Android:layout_width="fill_parent"
android:layout_height="wrap_content"
Android:background="#253853"
>
<ListView
Android:id="@+id/list"
Android:layout_width="match_parent"
android:layout_height="match_parent"
Android:cacheColorHint="#00000000"
android:divider="#2A4562"
Android:dividerHeight="3px"
android:listSelector="#264365"
Android:drawSelectorOnTop="false"
>
</ListView>
</LinearLayout>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFFFF</color>
<color name="transparency">#00000000</color>
<color name="title_bg">#1C86EE</color>
<color name="end_color">#A0cfef83</color>
<color name="black">#464646</color>
</resources>
MainActivity.xml
package com.ling.customlist;
import java.util.ArrayList;
import java.util.HashMap;
import xb.customlist.R;
import Android.R.array;
import android.app.Activity;
import Android.os.Bundle;
import android.widget.ArrayAdapter;
import Android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
ListView list;
String data[] = new String[]{
"China","UK","USA","Japan","German","Canada","ET","Narotu"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list =(ListView) findViewById(R.id.list);
SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.list_item,
new String[]{"title","img"}, new int[]{R.id.title,R.id.img});
list.setAdapter(adapter);
}
private ArrayList<HashMap<String, Object>> getData() {
ArrayList<HashMap<String, Object>> dlist = new ArrayList<HashMap<String,Object>>();
for(int i =0;i<data.length;i++){
HashMap<String, Object>map = new HashMap<String, Object>();
map.put("title", data[i]);
map.put("img", R.drawable.item_left2);
dlist.add(map);
}
return dlist;
}
}
⑤ android 圆角样式shape 的shape属性什么意思
shape官方给出了很多属性的解释,如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
><!-- 其中rectagle表示矩形,oval表示椭圆,line表示水平直线,ring表示环形 -->
<!-- 节点属性介绍如下 -->
<corners />
<!-- 节点1:corners (圆角)
android:radius 圆角的半径 值越大角越圆
android:topLeftRadius 左上圆角半径
android:topRightRadius 右上圆角半径
android:bottomLeftRadius 左下圆角半径
android:bottomRightRadius 右下圆角半径
-->
<gradient />
<!-- 节点2: gradient (背景颜色渐变)
android:startColor 起始颜色
android:centerColor 中间颜色
android:endColor 末尾颜色
android:angle 渐变角度,必须为45的整数倍。
android:type 渐变模式 默认是linear(线性渐变)radial(环形渐变)
android:centerX X坐标
android:centerY Y坐标
android:gradientRadius radial(环形渐变)时需指定半径
-->
<padding />
<!-- 节点3: padding (定义内容离边界的距离)
android:left 左部边距
android:top 顶部边距
android:right 右部边距
android:bottom 底部边距
-->
<size />
<!-- 节点4:size (大小)
android:width 指定宽度
android:height 指定高度
-->
<solid />
<!-- 节点5:solid (填充)
android:color 指定填充的颜色
-->
<stroke />
<!-- 节点6:stroke (描边)
android:width 描边的宽度
android:color 描边的颜色
把描边弄成虚线的形式"- - -":
android:dashWidth 表示'-'这样一个横线的宽度
android:dashGap 表示之间隔开的距离
-->
</shape></span>
⑥ 怎么在安卓代码中使用自己定义的shape
在drawable文件夹中创建bg_oval_shape/apk/res/android" android:shape="oval" > <solid android:color="#676767" /> </shape> 3.在需要添加oval的控件中引用,代码如下: <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bg_oval_shape"/>
⑦ android怎样在代码中创建shape圆oval
在drawable文件夹中创建bg_oval_shape.xml的xml文件
文件中添加如下代码
<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#676767"/>
</shape>
3.在需要添加oval的控件中引用,代码如下:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg_oval_shape"/>
⑧ android中如何使用shape来显示直角三角形
用一个rectangle的shape,再用一个rotate标签包裹这个shape,设置rotate标签的fromDegree为30,pivotX为0%,pivotY为100%。
意思就是对矩形做一个旋转,让它变成直角三角形。
⑨ android 怎样用shape画一个俩边半圆的按钮背景
用shape画一个俩边半圆的按钮,可以用图形画。
Circle方法用来画圆、椭圆、圆弧和饼分图。
画圆,Visual Basic需要给出这个圆的圆心位置和它的半径:“对象. Circle Step (x, y),半径,颜色”。
如果不指定对象,指定的就是当前的窗体。
用绘图区的标尺属性,可以使圆心置于绘图区域的中心处。
⑩ android如何创建平行四边形 shape 背景吗
作为选择到 @mmlooloo 的答案,其中归功于,我建议一个 xml 可绘制的解决方案 (因为你没有强调什么样的你正在寻找的解决方案)。在下面的示例使用一般 View ,但您可以使用任何其他。
这里是View
<View
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:background="@drawable/shape" />
和 shape.xml 本身
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="" >
<!-- Colored rectangle-->
<item>
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="40dp" />
<solid android:color="#13a89e" />
</shape>
</item>
<!-- This rectangle for the left side -->
<!-- Its color should be the same as layout's background -->
<item
android:right="100dp"
android:left="-100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
<!-- This rectangle for the right side -->
<!-- Their color should be the same as layout's background -->
<item
android:right="-100dp"
android:left="100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>