天天看點

安卓常用的三行布局

第一次寫部落格,記錄自己在日常開發中用到的實用的技術和技巧,與各位共享;

最近在app開發當中涉及到資訊方面的布局,舉個例子?

安卓常用的三行布局

在上面這個新聞詳情界面,布局就是标準的三行布局: 上面一個titlebar,中間是content,下面是互動;

類似這樣的布局,快速而高效的就是利用RelativeLayout:

最上方是一個自定義的titlebar,當然換成你喜歡xxbar都可以

<include layout="@layout/title_bar"/>      

中面是個scrollview,其中需要below我們的titlebar,還需要above我們下邊的互動欄

<ScrollView
    android:layout_above="@+id/ll_introduce"
    android:layout_below="@+id/title_bar"
    android:id="@+id/news_scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >      

最後是我們的互動布局,隻需要alignParentBottom,因為我們的scrollview滑動的同時也需要沉底

<LinearLayout
    android:id="@+id/ll_introduce"
    android:focusableInTouchMode="true"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">      

大功告成,是不是很簡單,這樣做的好處是高度自适應,并且不會覆寫我們的底部布局,over;