ShapeDrawable(1)
来源:互联网 发布:windows文件监控 编辑:程序博客网 时间:2024/06/10 18:32
一、
select_prj_btn.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="5dp" /> <padding android:bottom="20dp" android:left="20dp" android:right="20dp" android:top="20dp" /> <solid android:color="#FF89DDDD" /> <stroke android:width="1dp" android:color="#318E8C" /></shape>activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Button android:id="@+id/select_prj_btn" android:layout_width="70dp" android:layout_height="50dp" android:background="@drawable/select_prj_btn" android:text="选择项目" /></RelativeLayout>效果如下图:
问:为什么显示不全呢?算一下啊:横向70dp-20dp*2=30dp;纵向50dp-20dp*2=10dp,编辑区太小,所以显示不全;
在如下:
select_prj_btn.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="5dp" /> <padding android:bottom="20dp" android:left="20dp" android:right="20dp" android:top="20dp" /> <solid android:color="#FF89DDDD" /> <stroke android:width="1dp" android:color="#318E8C" /></shape>activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Button android:id="@+id/select_prj_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/select_prj_btn" android:text="选择项目" /></RelativeLayout>结果图如下:
我得出的结论如下:android:layout_width="dimesion|match_parent" 和android:layout_height="dimesion|match_parent"说的是整个Button
而android:layout_width="wrap_content" 和android:layout_height="wrap_content"说的是编辑区正好包含内容,所以这时候说的是编辑区。
二、
shape的模型如下:
边框由stroke描述;编辑区由padding决定;边框内(包括编辑区)的填充色由solid决定;四个角由corner决定(有边框,作用于边框外边;无边框也作用于外边)。编辑区是存放内容的。
三、
由上面论述可以得出:Button的background属性引用了select_prj_btn.xml后,text是放在了编辑区内,当layout_width="wrap_content" layout_height="wrap_content" 作用于编辑区,让编辑区包裹内容;当layout_width="70dp" layout_height="50dp"作用于整个Button大小,而整个shape正好充满这个Button大小范围内,shape中的padding都是20dp,那么编辑区变得就很小了,放不下text了。
四、
任何View都有背景,任何背景都有编辑区,将某个View2放到这个View1里面,其实就是放到了View1中的编辑区里面了;View大小和背景大小一样大。
这是我的个人判断,请大家指正!
- ShapeDrawable(1)
- ShapeDrawable
- ShapeDrawable
- ShapeDrawable
- ShapeDrawable
- ShapeDrawable
- Android ShapeDrawable
- ShapeDrawable 资源
- Android ShapeDrawable
- ShapeDrawable资源..
- ShapeDrawable资源
- ShapeDrawable资源
- ShapeDrawable放大镜的案例
- Graphics->Drawable->ShapeDrawable
- Android开发之ShapeDrawable
- Android开发之ShapeDrawable
- android ShapeDrawable实例
- android 放大镜--ShapeDrawable妙用
- error LNK2019: 无法解析的外部符号
- Android 框架简介
- 数据库自联表查询
- 编写健壮的Bash shell脚本
- hdu1874(dijkstra)
- ShapeDrawable(1)
- 几个Eclipse超酷插件
- juqery之匿名函数 extend each this
- try{} catch{}
- c语言文件操作(另一个版本)
- Unity3D NGUI UIButtonTween动画事件详解
- Android深入浅出之Binder机制
- 内存分析
- C++ 编程思想 第二章习题