本帖最後由 ray 於 2019-9-28 11:26 編輯
1.Gradle App:
compile 'com.android.support:design:23.0.+'
2.Layout/main.xml:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fab"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:src="@drawable/ic_action_add"
app:layout_anchor="@+id/appbar"
app:layout_anchorGravity="bottom|right|end" />
3.GDD01.java:
initFloatingActionButton()
FloatingActionButton fab = (FloatingActionButton)this.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Snackbar.make(mCoordinatorLayout,"你點擊了浮動的+按鈕",Snackbar.LENGTH_SHORT).show();
}
});
initBanner()
mCollapsingToolbarLayout.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Snackbar.make(mCoordinatorLayout,"你點擊了上方廣告Banner",Snackbar.LENGTH_SHORT).show();
}
});
initDataset()
if(i%2 == 0)
movie.setThumbnail(R.drawable.milkyway);
else
movie.setThumbnail(R.drawable.peacock);
4.HippoCustomRecyclerViewAdapter.java:
ViewHolder(View view):
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos= (int) v.getTag();
Toast.makeText(mContext,"你點選的是第 "+pos+" 部電影",Toast.LENGTH_SHORT).show();
}
});
onBindViewHolder(ViewHolder viewHolder, int position):
viewHolder.itemView.setTag(position);
Movie mv=mDataSet.get(position);
viewHolder.getTextView().setText(mv.getName());
Drawable bmp=mContext.getDrawable(mv.getThumbnail());
viewHolder.getImageView().setImageDrawable(bmp); |