简体   繁体   中英

How to create this kind of view in Android?

在此处输入图片说明

I want to use this kind of UI in my Contact Android App. The picture shown resizes itself when we scroll down much and the Name 'XYZ' finally become the title of the action bar. Also how can I put textview over imageview?

What you're looking for is CollapsingToolbarLayout .

The general approach to this kind of animations is to use top level CoordinatorLayout which contain two children: the first child is the "collapsible" content, and the second is "body". The general hierarchy looks like this:

CoordinatorLayout
  |-AppBarLayout
    |-CollapsingToolbarLayout
      |-Toolbar
  |-ScrollView

The second child must not be ScrollView - use any ViewGroup that suits your needs, and just add the following attribute to its description in xml :

app:layout_behavior="@string/appbar_scrolling_view_behavior"

the above string resource should map to AppBarLayout.ScrollingViewBehavior (just use android.support.design.widget.AppBarLayout$ScrollingViewBehavior as this resource's value).

There is very good tutorial on this kind of animations on Codepath .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM