日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android CardView卡片布局 标签: 控件

發布時間:2023/12/10 Android 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android CardView卡片布局 标签: 控件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

CardView介紹

CardView是Android?5.0系統引入的控件,相當于FragmentLayout布局控件然后添加圓角及陰影的效果;CardView被包裝為一種布局,并且經常在ListView和RecyclerView的Item布局中,作為一種容器使用。CardView應該被使用在顯示層次性的內容時;在顯示列表或網格時更應該被選擇,因為這些邊緣可以使得用戶更容易去區分這些內容。

使用

先看效果?
?
首先在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.CardViewandroid:id="@+id/cardView"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="10dp"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="100dp"><ImageViewandroid:layout_width="150dp"android:layout_height="match_parent"android:layout_margin="5dp"android:scaleType="centerCrop"android:src="@drawable/sng" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:padding="5dp"android:text="棒冰行動"android:textSize="18sp"android:textStyle="bold" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:padding="5dp"android:text="棒冰行動,公益傳播設計夏令營" /></LinearLayout></LinearLayout></android.support.v7.widget.CardView></LinearLayout>

在MainActivity.Java下文件

public class MainActivity extends AppCompatActivity {private CardView cardView;@Overrideprotected 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);//設置圖片距離陰影大小 } }

?

總結

以上是生活随笔為你收集整理的Android CardView卡片布局 标签: 控件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。