标签:des android style blog http io ar color os
首先来看我们要实现的效果:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 一个层叠效果,通过阴影表现出立体效果 --> <item><!-- 阴影效果 --> <shape android:shape="rectangle" > <solid android:color="#CABBBBBB" /><!-- 阴影的颜色 --> <corners android:radius="2dp" /><!-- 圆角 --> </shape> </item> <item android:bottom="2dp" android:left="0dp" android:right="0dp" android:top="0dp"><!-- 距底部2dp,漏出上面那个item,使其可以显现出阴影 --> <shape android:shape="rectangle" > <solid android:color="@android:color/white" /><!-- item颜色 --> <corners android:radius="2dp" /> </shape> </item> </layer-list>
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#ca39883d" /> <corners android:radius="2dp" /> </shape> </item> <item android:bottom="2dp" android:left="0dp" android:right="0dp" android:top="0dp"> <shape android:shape="rectangle" > <solid android:color="#ca4fbb5f" /> <corners android:radius="2dp" /> </shape> </item> </layer-list>
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/card_state_pressed" android:state_pressed="true" /> <item android:drawable="@drawable/card_background" /> </selector>
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="15dp" android:paddingRight="15dp" android:descendantFocusability="beforeDescendants"><!-- 为突出卡片效果,需设置左右padding,上下通过listView的divider设置 --> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="15dp" android:paddingTop="15dp" android:paddingBottom="15dp" android:paddingRight="15dp" android:background="@drawable/card_background_selector" android:descendantFocusability="afterDescendants"><!-- 给每个item增加background --> <TextView android:id="@+id/line1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text"/> </LinearLayout> </FrameLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#e2e4fe"><!-- 此处需设置listView背景 --> <ListView android:id="@+id/card_listView" android:layout_width="match_parent" android:layout_height="match_parent" android:listSelector="@android:color/transparent" android:cacheColorHint="@android:color/transparent" android:divider="@null" android:dividerHeight="10dp" /><!-- 一定要将divider设置为@null,dividerHeight控制卡片上下距离 --> </LinearLayout>
public class MainActivity extends Activity { private ListView listView; private static final String[] data = { "北京", "上海", "武汉", "广州", "西安", "南京", "合肥","上海", "武汉", "广州", "西安", "南京", "合肥" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.card_listView); /*添加头和尾*/ listView.addHeaderView(new View(this)); listView.addFooterView(new View(this)); listView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item_card, R.id.line1, data)); } }
标签:des android style blog http io ar color os
原文地址:http://blog.csdn.net/chdjj/article/details/41546477