标签:android style class blog code http
人们都说扁平化是从IOS和WindowsPhone那边吹过来的邪风,但是不可否认:扁平化是我见过的最舒服、最自然的表现方式。从开发角度上来讲,扁平化的设计可以使得我们从许多屏幕适配和尺寸调节的工作中解放出来(虽然只是那么一点点),更加关注功能;而在在使用层面上,只要文化水平不是特别地低(没有恶意),拟物化的那点提示作用也不是那么明显,当然这里不是说拟物化不好,总之:相对于其他表现方式,扁平化碉堡了。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="5dp" />
<solid android:color="@android:color/white" />
<stroke
android:width="0.5dp"
android:color="@android:color/black" />
</shape>
我们的设计中还包括:用户点击按钮时,背景色变为蓝色。所以,上面的drawable资源也仅仅是默认状态下的显示,下面我们再创建一个扁平化Button按下时的效果:
bordered_black_blue_bg_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="5dp" />
<!-- 自定义的浅蓝色 -->
<solid android:color="@color/blue" />
<stroke
android:width="0.5dp"
android:color="@android:color/black" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bordered_black_blue_bg_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/bordered_black_blue_bg"/>
</selector><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="5dp" />
<solid android:color="@android:color/white" />
<stroke
android:width="0.5dp"
android:color="@android:color/black" />
</shape><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bordered_black_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="@dimen/default_padding" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:maxWidth="@dimen/info_item_max_text_width"
android:text="chinese address" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_large"
android:text="北京市\n朝阳区\n大望路\n34号n34号n34号n34号n34号n34号" />
</LinearLayout><LinearLayout 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"
android:orientation="vertical"
android:padding="@dimen/default_padding" >
<!-- 这是我自定义的View,对应于上图中的蓝色部分,可作为你的练习作业 -->
<org.xiaom.butler.view.TopNav
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:text="Baby Home Care Center"
android:textSize="@dimen/text_size_larger"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="宝贝家早教中心"
android:textSize="@dimen/text_size_large" />
<!-- 此Button使用了之前定义的扁平化背景@drawable/selector/selector_button_normal_bg -->
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:background="@drawable/selector_button_normal_bg"
android:text="Show Taxi Card"
android:textColor="@android:color/black"
android:textSize="@dimen/text_size_large"
android:textStyle="bold" />
<!-- 注意divider及dividerHeight这两个属性 -->
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:divider="@null"
android:dividerHeight="@dimen/list_dirver_height"
android:paddingBottom="@dimen/list_view_padding_v"
android:paddingTop="@dimen/list_view_padding_v" >
</ListView>
</LinearLayout>Android自定义控件背景及其Drawable以实现扁平化,布布扣,bubuko.com
Android自定义控件背景及其Drawable以实现扁平化
标签:android style class blog code http
原文地址:http://blog.csdn.net/mthhk008/article/details/31388515