卡片view
2015-09-11 09:12
363 查看
美学:cardview更加美观的一个重要原因是平滑渐进
一,cardview内容到groupview之间嵌套一个阴影,造成一种递进效果
二,cardview通常有一个微小的圆角,比突兀的直角更符号美学
CardView 属于Support v7 里面的新的Widget. 扩展于FrameLayout,
UI显示主要包括
1.边框圆角
2.有阴影Shadow
用来突出个性,比如展览,相册等。
重要的几个属性:
card_view:cardCornerRadius="10dp" 圆角的半径
card_view:cardElevation="24dp" 阴影shadow
SeekBar用来测试这2个值的。
build.gradle 加入依赖
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
}
一,cardview内容到groupview之间嵌套一个阴影,造成一种递进效果
二,cardview通常有一个微小的圆角,比突兀的直角更符号美学
CardView 属于Support v7 里面的新的Widget. 扩展于FrameLayout,
UI显示主要包括
1.边框圆角
2.有阴影Shadow
用来突出个性,比如展览,相册等。
<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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.example.gaofeng.recyclerviewdemo.CardViewActivity" xmlns:card_view="http://schemas.android.com/apk/res-auto" > <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="wrap_content" card_view:cardBackgroundColor="@android:color/white" android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" card_view:cardCornerRadius="10dp" card_view:cardElevation="24dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin" > <ImageView android:id="@+id/img" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/cat0" android:layout_centerHorizontal="true" android:scaleType="fitCenter" /> <TextView android:id="@+id/text_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/img" android:layout_centerHorizontal="true" android:text="This is a card view" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" /> </RelativeLayout> </android.support.v7.widget.CardView> <SeekBar android:layout_below="@+id/card_view" android:id="@+id/seek1" android:layout_marginTop="10dp" android:layout_width="150dp" android:layout_height="30dp" /> <SeekBar android:layout_below="@+id/seek1" android:id="@+id/seek2" android:layout_marginTop="10dp" android:layout_width="150dp" android:layout_height="30dp" /> </RelativeLayout>
重要的几个属性:
card_view:cardCornerRadius="10dp" 圆角的半径
card_view:cardElevation="24dp" 阴影shadow
SeekBar用来测试这2个值的。
package com.example.gaofeng.recyclerviewdemo; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.support.v7.widget.CardView; import android.view.Menu; import android.view.MenuItem; import android.widget.SeekBar; public class CardViewActivity extends ActionBarActivity { CardView cardView = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card_view); cardView = (CardView) findViewById(R.id.card_view); SeekBar seek1 = (SeekBar) findViewById(R.id.seek1); SeekBar seek2 = (SeekBar) findViewById(R.id.seek2); seek1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (b) { cardView.setCardElevation(i);//shadow } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); seek2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (b) { cardView.setRadius(i);//圆角大小设置 } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); }有的5.0的模拟器看不到 Shadow 建一个Nexus 1080的模拟器 可以看到。
build.gradle 加入依赖
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
}
相关文章推荐
- 学习RecyclerView和CardView
- CardView设置item的margin问题
- Android Material Design之在RecyclerView中嵌套CardView实现
- CardView初级使用
- RecyclerView,SwipeRefreshLayout,CardView最新控件的使用
- AndroidL系列-CardView
- Android零基础入门第71节:CardView简单实现卡片式布局
- cardview使用
- 【FastDev4Android框架开发】实例解析之SwipeRefreshLayout+RecyclerView+CardView(三十五)
- 【FastDev4Android框架开发】CardView完全解析与RecyclerView结合使用(三十二)
- Android之RecycleView和CardView
- CardView的使用
- Android 中简单使用RecyclerView 和CardView
- Android Study Material Design 十一 之CardView窥探
- RecyclerView 、CardView、FAB、CoordinatorLayout、ToolBar、Snackbar、CollapsingToolbarLayout、NavigationView
- 5.0 recycleview 和cardview基本使用
- Material Design控件相关使用
- Eclipse 引用CardView这样的5.0控件
- Android CardView使用
- CardView API19及以下圆角效果兼容