Android控件CardView實現(xiàn)卡片布局
CardView介紹
CardView是Android 5.0系統(tǒng)引入的控件,相當于FragmentLayout布局控件然后添加圓角及陰影的效果;CardView被包裝為一種布局,并且經(jīng)常在ListView和RecyclerView的Item布局中,作為一種容器使用。CardView應該被使用在顯示層次性的內(nèi)容時;在顯示列表或網(wǎng)格時更應該被選擇,因為這些邊緣可以使得用戶更容易去區(qū)分這些內(nèi)容。
使用
先看效果
首先在build.gradle文件添加依賴庫
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.2.0' compile 'com.android.support:cardview-v7:24.2.0' }
布局文件main.html文件下
<?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="match_parent"> <android.support.v7.widget.CardView android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="100dp"> <ImageView android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="5dp" android:scaleType="centerCrop" android:src="@drawable/sng" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:text="棒冰行動" android:textSize="18sp" android:textStyle="bold" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:text="棒冰行動,公益?zhèn)鞑ピO計夏令營" /> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView> </LinearLayout>
在MainActivity.java下文件
public class MainActivity extends AppCompatActivity { private CardView cardView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cardView = (CardView)findViewById(R.id.cardView); cardView.setRadius(8);//設置圖片圓角的半徑大小 cardView.setCardElevation(8);//設置陰影部分大小 cardView.setContentPadding(5,5,5,5);//設置圖片距離陰影大小 } }
好,已結束CardView難度不大,當是實用性及及效果是非常棒的,值得你擁有!
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Android利用ViewPager實現(xiàn)帶小圓球的圖片滑動
這篇文章主要為大家詳細介紹了Android利用ViewPager實現(xiàn)帶小圓球的圖片滑動,并且只有第一次安裝app時才出現(xiàn)歡迎界面具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-11-11android開發(fā)教程之獲取power_profile.xml文件的方法(android運行時能耗值)
在Android手機中,對于手機中的每個部件(cpu、led、gps、3g等等)運行時對應的能耗值都放在power_profile.xml文件中2014-02-02android ItemTouchHelper實現(xiàn)可拖拽和側(cè)滑的列表的示例代碼
本篇文章主要介紹了ItemTouchHelper實現(xiàn)可拖拽和側(cè)滑的列表的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02Android解析JSON格式數(shù)據(jù)的兩種方式(JSONObject和Gson)
json數(shù)據(jù)的解析相對而言,還是比較容易的,實現(xiàn)的代碼也十分簡單,下面這篇文章主要給大家介紹了關于Android解析JSON格式數(shù)據(jù)的兩種方式,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-07-07Android實現(xiàn)評論欄隨Recyclerview滑動左右移動
這篇文章主要介紹了Android實現(xiàn)評論欄隨Recyclerview滑動左右移動效果,仿約會吧應用詳情頁實現(xiàn),感興趣的小伙伴們可以參考一下2016-05-05