iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 28
0
Mobile Development

iOS Developer Learning Android系列 第 28

iOS Developer Learning Android. Lesson 28 - 伸縮Banner + 瀑布流 + CardView (首頁大改造)

明天要上架了,所以來幫首頁變臉一下
今天是最沒有技術的一天(雖然之前也沒有)

本日效果

幾個重點

  1. CardView: 就是FrameLayout的一種,但是加了一些現在常用的設計,例如圓角/陰影等等
    1. 常用屬性
      app:cardBackgroundColor:設定卡片的背景色(注意不是backgroundColor)
      app:cardCornerRadius:設定卡片圓角的大小
      app:cardElevation:設置卡片陰影的大小
      app:cardUseCompatPadding:在API v21 +中添加內邊距與以前版本有相同的測量。
      app:contentPadding:添加左、上、右、下的內邊距
      app:contentPaddingBottom:添加下方的內邊距
      app:contentPaddingLeft:添加左邊的內邊距
      app:contentPaddingRight:添加右邊的內邊距
      app:contentPaddingTop:添加上方的內邊距
    2. 點擊波紋效果
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
  1. 瀑布流: 透過LayoutManager就可達成了,
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL)); 一行搞定
    1. StaggeredGridLayoutManager就是瀑布流
    2. 3代表三欄
    3. VERTICAL垂直滾動
  2. 在RecycleView.ViewHolder的如何startActivity?
    view.getContext();就可以拿到Activity了
  3. 伸縮Banner: 不用寫code, 透過layout即可
    1. 先在AndroidMenifest把Activity的theme設成NoActionBar
    2. layout結構:
      1. CoordinatorLayout
        1. AppBarLayout
          1. CollapsingToolbarLayout
            1. ImageView
            2. Toolbar
        2. NestedScrollView
          1. RecyclerView
    3. 最後在Activity裡findViewById取得tool用setSupportActionBar塞回去即可

注意!!

如果在AndroidMenifest把Activity的label改掉,會蓋掉app_name= =
用setTitle則不會

參考資料

今天的範例程式

可以去 https://github.com/mark33699/IDLA 看一下順便給顆⭐️


如果你喜歡我的影片別忘了按讚分享加訂閱,開啟紅色的小鈴鐺,我們明天見~


上一篇
iOS Developer Learning Android. Lesson 27 - APP Widget (讓user不用開你的APP就能用你的APP)
下一篇
iOS Developer Learning Android. Lesson 29 -上架 (寫APP就是要上架啊~不然要幹嘛)
系列文
iOS Developer Learning Android30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言