1.activity_main.xml 2.MainActivity.class package com.example.administrator.myfirst; import android.os.Bundle; import android.support.v7.app.AppCompatA ...
1.activity_main.xml
<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="棒冰行動,公益傳播設計夏令營" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
2.MainActivity.class
package com.example.administrator.myfirst;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
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);//設置圖片距離陰影大小
}
}