ایجاد یک cardview ساده در اندروید

شنبه 3 تیر 1396

در این مقاله قصد داریم یک سورس درست نماییم که این سورس به این صورت است که شما می توانید یک cardview ساده را ایجاد نمایید در این مقاله مرحله به مرحله ی ایجاد یک cardview را به شما توضیح خواهم داد.

ایجاد یک cardview ساده در اندروید

ابتدا در قسمت build را باید باز نمایید:

قطعه کد زیر را قرار می دهید:

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'

خروجی به صورت زیر خواهد بود:

در کلاس قطعه کد زیر را قرار دهید:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

در لایه هم قطعه کد زیر را قرار دهید:

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.cardview_android_examplescom.MainActivity">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        card_view:cardCornerRadius="6dp"
        card_view:cardElevation="6dp"
        card_view:contentPadding="25dp"
        card_view:cardBackgroundColor="#2196F3"

        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="SIMPLE \n CARDVIEW"
            android:textSize="30sp"
            android:textStyle="bold"
            android:textColor="#E3F2FD"
            />
    </android.support.v7.widget.CardView>

</RelativeLayout>

خروجی به صورت زیر خواهد بود:

فایل های ضمیمه

برنامه نویسان

نویسنده 3355 مقاله در برنامه نویسان

کاربرانی که از نویسنده این مقاله تشکر کرده اند

در صورتی که در رابطه با این مقاله سوالی دارید، در تاپیک های انجمن مطرح کنید