cardview使用笔记

demo图

首先导入
…\android-sdk\extras\android\support\v7\cardview
lib项目

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"
     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=".MainActivity"

    >
    <android.support.v7.widget.CardView
        xmlns:cardview="http://schemas.android.com/apk/res-auto"  
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        cardview:cardCornerRadius="10dp"
        cardview:cardBackgroundColor="@android:color/white"
        cardview: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/ic_launcher"
            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>

java

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

         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) {  

                }  
            });  
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值