current position:Home>Appbarlayout of Android realizes the effect of hovering adsorption and scaling, and Android develops games

Appbarlayout of Android realizes the effect of hovering adsorption and scaling, and Android develops games

2022-02-04 16:27:01 m0_ sixty-four million six hundred and four thousand six hundre

<android.support.design.widget.CoordinatorLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

android:layout_width=“match_parent”

android:layout_height=“match_parent”>

<android.support.v4.widget.NestedScrollView

android:layout_width=“match_parent”

android:layout_height=“match_parent”

app:layout_behavior="@string/appbar_scrolling_view_behavior" >

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

app:layout_behavior="@string/appbar_scrolling_view_behavior" >

``

app:layout_behavior="@string/appbar_scrolling_view_behavior" >

CollapsingToolbarLayout:


CollapsingToolbarLayout It's also android.support:design Supported controls in package , Inherited from FrameLayout. Mainly used to realize ToolBar Stretching effect of , And must be AppBarLayout The direct son of View;

The inheritance structure is as follows :

java.lang.Object

↳ android.view.View

↳ android.view.ViewGroup

↳ android.widget.FrameLayout

↳ android.support.design.widget.CollapsingToolbarLayout

The main methods used are as follows :

  • setCollapsedTitleGravity

void setCollapsedTitleGravity(int gravity)

Set the horizontal alignment of the folded title and vertical gravity , When there is extra space in the fold boundary that exceeds the space required by the title itself , This alignment will be used

dependent XML attribute :

CollapsingToolbarLayout_collapsedTitleGravity

2.setExpandedTitleGravity

void setExpandedTitleGravity(int gravity)

Set the horizontal alignment of the expanded title and vertical gravity , When there is extra space in the extension boundary that exceeds the space required by the title itself , This alignment will be used .

dependent XML attribute :

CollapsingToolbarLayout_expandedTitleGravity

3.setExpandedTitleTextColor

void setExpandedTitleTextColor(ColorStateList colors)

Set the text color of the expanded title .

4.setCollapsedTitleTextColor

void setCollapsedTitleTextColor(ColorStateList colors)

Set the text color of the collapsed title .

5.setCollapsedTitleTypeface

void setCollapsedTitleTypeface( Font font )

Set the font used to collapse the title .

5.setExpandedTitleMarginBottom

void setExpandedTitleMarginBottom(int margin)

Sets the bottom expanded Title margin in pixels .

dependent XML attribute :

CollapsingToolbarLayout_expandedTitleMarginBottom

  • Fix Toolbar

app:layout_collapseMode=“pin”

6. See the documentation for more methods

About AppBarLayout The Three Musketeers' combination is almost the same , If you want to know more, you can consult the official documents , The above shows the connection .

In particular :

Three swordsmen used together , Can make some cool UI effect .

But the premise must be met :AppbarLayout As CoordinatorLayout The direct son of View, and CollapsingToolbarLayout As AppbarLayout The direct son of View , otherwise , The effect shown above will not be realized .

AppbarLayout Example show


1. Imitation [ Open eyes App] Personal centered effect

  • .xml Layout file :
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

xmlns:fresco=“http://schemas.android.com/apk/res-auto”

xmlns:imagetext=“http://schemas.android.com/apk/res-auto”

xmlns:app=“http://schemas.android.com/apk/res-auto”

android:orientation=“vertical”

android:background="@color/colorWhite"

<android.support.design.widget.AppBarLayout

android:id="@+id/center_appbar_layout"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

app:elevation=“0dp”

android:background="@color/colorWhite"

android:fitsSystemWindows=“true”

<android.support.design.widget.CollapsingToolbarLayout

android:id="@+id/collapsing_toobar"

android:layout_width=“match_parent”

android:layout_height=“260dp”

app:layout_scrollFlags=“scroll|exitUntilCollapsed”

app:contentScrim="@color/colorGraylight"

fresco:expandedTitleTextAppearance="@style/style_textsize1"

fresco:collapsedTitleTextAppearance="@style/style_textsize"

fresco:collapsedTitleGravity=“left”

fresco:expandedTitleMarginTop=“185dp”

fresco:expandedTitleGravity=“left”

fresco:expandedTitleMarginStart=“30dp”

<FrameLayout

app:layout_scrollFlags=“scroll”

android:layout_width=“match_parent”

android:layout_height=“180dp”>

<com.facebook.drawee.view.SimpleDraweeView

android:id="@+id/avatar_max"

android:layout_width=“match_parent”

android:layout_height=“170dp” />

<com.facebook.drawee.view.SimpleDraweeView

android:layout_marginLeft=“20dp”

android:layout_gravity=“bottom”

android:id="@+id/avatar_min"

android:layout_width=“70dp”

android:layout_height=“70dp”

fresco:actualImageScaleType=“centerCrop”

fresco:placeholderImageScaleType=“centerCrop”

fresco:roundedCornerRadius=“50dp”

/>

<FrameLayout

android:layout_marginTop=“180dp”

app:layout_scrollFlags=“scroll”

android:layout_width=“match_parent”

android:layout_height=“50dp”

<Button

android:id="@+id/edit_btn"

android:layout_width=“60dp”

android:layout_height=“20dp”

android:layout_marginRight=“20dp”

android:layout_gravity=“right|center_vertical”

android:background="@drawable/login_btn"

android:gravity=“center”

android:text=“ Edit information ”

android:textColor="@color/colorBlacklight"

android:textSize=“10sp” />

<TextView

android:layout_marginTop=“230dp”

app:layout_scrollFlags=“scroll”

android:textSize=“10sp”

android:id="@+id/date"

android:layout_marginLeft=“20dp”

android:text=“2018.07.08 register ”

android:textColor="@color/colorGraylight"

android:layout_width=“match_parent”

android:layout_height=“wrap_content” />

<android.support.v7.widget.Toolbar

android:id="@+id/toolbar"

android:layout_width=“match_parent”

app:layout_collapseMode=“pin”

android:layout_height="?attr/actionBarSize"

</android.support.v7.widget.Toolbar>

</android.support.design.widget.CollapsingToolbarLayout>

<LinearLayout

android:gravity=“center_vertical”

android:layout_marginTop=“20dp”

android:background="@color/colorGrayalpha"

android:layout_width=“match_parent”

android:layout_height=“70dp”>

<openeyes.dr.openeyes.widget.CustomImageTextView

android:id="@+id/works"

android:layout_marginLeft=“40dp”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

imagetext:image="@drawable/works2"

imagetext:text="@string/works"

imagetext:textColor="@color/colorGraylight"

</openeyes.dr.openeyes.widget.CustomImageTextView>

<openeyes.dr.openeyes.widget.CustomImageTextView

android:id="@+id/attention"

android:layout_marginLeft=“90dp”

android:layout_w

《Android Summary of learning notes + Latest mobile architecture video + Big Android interview questions + Project actual combat source code handout 》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 Full content open source sharing

idth=“wrap_content”

android:layout_height=“wrap_content”

imagetext:image="@drawable/attention6"

imagetext:text="@string/attention"

imagetext:textColor="@color/colorGraylight"

</openeyes.dr.openeyes.widget.CustomImageTextView>

<openeyes.dr.openeyes.widget.CustomImageTextView

android:id="@+id/fans"

android:layout_marginLeft=“90dp”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

imagetext:image="@drawable/works2"

imagetext:text="@string/fans"

imagetext:textColor="@color/colorGraylight"

</openeyes.dr.openeyes.widget.CustomImageTextView>

</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView

android:id="@+id/recycle_state"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

app:layout_behavior="@string/appbar_scrolling_view_behavior"

/>

</android.support.design.widget.CoordinatorLayout>

  • java file :

public class PersonPageActivity extends SwipeBackActivity {

@BindView(R.id.avatar_max)

SimpleDraweeView avatarBackground;

@BindView(R.id.avatar_min)

SimpleDraweeView avatarUser;

@BindView(R.id.date)

TextView registerDate;

@BindView(R.id.works)

CustomImageTextView works;

@BindView(R.id.attention)

CustomImageTextView attention;

@BindView(R.id.fans)

CustomImageTextView fans;

@BindView(R.id.center_appbar_layout)

AppBarLayout appBarLayout;

@BindView(R.id.collapsing_toobar)

CollapsingToolbarLayout collToobar;

@BindView(R.id.toolbar)

Toolbar toolbar;

@BindView(R.id.recycle_state)

RecyclerView recyclerView;

private SharedPreferences sharedPreferences = MyApplication.sharedPreferences;

private HistoryDB db;

private List details = null;

private DynamicStateRecyclerAdapter adapter;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_person_page);

ButterKnife.bind(this);

initView();

initData();

}

private void initData() {

db = new HistoryDB();

details= db.loadHistoryByUserId(sharedPreferences.getString(“userId”,“000”));

if (details==null||details.size()==0){

}else {

Collections.reverse(details);

adapter = new DynamicStateRecyclerAdapter(details,this);

LinearLayoutManager manager = new LinearLayoutManager(this);

manager.setOrientation(LinearLayoutManager.VERTICAL);

recyclerView.setLayoutManager(manager);

recyclerView.setAdapter(adapter);

recyclerView.setItemAnimator(new DefaultItemAnimator());// Add default animation

// Set up RecyclerView Of item Monitoring events

setOnItemClickListener();

}

}

private void setOnItemClickListener() {

adapter.setOnItemClickListener(new DynamicStateRecyclerAdapter.OnItemClickListener() {

@Override

public void onItemClick(View itemview, DynamicStateRecyclerAdapter.MyViewHolder childview, int position) {

initVideoDetail( position);// Initialize the video detail interface data and realize jump

}

});

}

/**

  • Initialize video detail interface data , Jump to the video details interface

  • */

private void initVideoDetail(int position) {

Intent intent = new Intent(PersonPageActivity.this, VideoDetailActivity.class);

Bundle bundle = new Bundle();

bundle.putString(“title”,details.get(position).getTitle());// Get the title

bundle.putString(“time”, details.get(position).getDetail());

bundle.putString(“desc”, details.get(position).getDesc());// Video description

bundle.putString(“blurred”, details.get(position).getBlurred());// Fuzzy picture address

bundle.putString(“feed”, details.get(position).getPhoto());// Picture address

bundle.putString(“video”, details.get(position).getVideo());// Video address

bundle.putInt(“collect”, details.get(position).getCollect());// Collection volume

bundle.putInt(“share”, details.get(position).getShare());// Share volume

bundle.putInt(“reply”, details.get(position).getReply());// Number of replies

intent.putExtras(bundle);

startActivity(intent);

}

private void initView() {

avatarBackground.setImageURI(Uri.parse(sharedPreferences.getString(“userIcon”,"")));

avatarUser.setImageURI(Uri.parse(sharedPreferences.getString(“userIcon”,"")));

toolbar.setTitle(sharedPreferences.getString(“userName”,""));// Set title

collToobar.setExpandedTitleColor(getResources().getColor(R.color.colorBlack));

setSupportActionBar(toolbar);

getSupportActionBar().setDisplayShowHomeEnabled(true);

toolbar.setNavigationIcon(R.drawable.back_black);

toolbar.setNavigationOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

finish();

}

});

}

@OnClick(R.id.attention)

public void onClick(){

startActivity(new Intent(this,MyAttentionActivity.class));

}

}

Effect display :

##### Open eyes app Personal center

2. Imitation [ Open eyes App] Search hover interface :

  • .xml Layout file :
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

xmlns:app=“http://schemas.android.com/apk/res-auto”

android:orientation=“vertical”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“50dp”>

<openeyes.dr.openeyes.widget.SearchEditText

android:id="@+id/search_editext"

android:layout_marginLeft=“20dp”

android:background="@drawable/shape_search"

android:layout_width=“300dp”

android:layout_height=“30dp”

android:paddingLeft=“15dp”

android:paddingRight=“15dp”

android:gravity=“start|center_vertical”

android:imeOptions=“actionSearch”

android:singleLine=“true”

android:hint=“ Search video 、 author 、 Users and labels ”

android:textSize=“13sp”

/>

<TextView

android:id="@+id/cancle_main"

android:textColor="@color/colorBlacklight"

android:gravity=“center”

android:text=“ Cancel ”

android:layout_width=“match_parent”

android:layout_height=“match_parent” />

<FrameLayout

android:id="@+id/history_fl"

android:visibility=“gone”

android:layout_width=“match_parent”

android:layout_height=“50dp”

<TextView

android:layout_gravity=“center_vertical”

android:layout_marginLeft=“20dp”

android:textSize=“20sp”

android:text=“ Search history ”

android:textColor="@color/colorBlack"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content” />

<TextView

android:id="@+id/delete_history"

android:layout_marginRight=“20dp”

android:layout_gravity=“center_vertical|right”

android:textColor="@color/colorAniBtns"

android:gravity=“center”

android:text=“ Empty ”

android:textSize=“13sp”

android:layout_width=“50dp”

android:layout_height=“wrap_content” />

<android.support.design.widget.CoordinatorLayout

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

android:background="@color/colorWhite"

<android.support.design.widget.AppBarLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="@color/colorWhite"

<android.support.v7.widget.RecyclerView

android:id="@+id/search_history_rv"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

app:layout_scrollFlags=“scroll”

</android.support.v7.widget.RecyclerView>

<TextView

android:layout_marginLeft=“20dp”

android:text=“ Hot search keywords ”

android:textSize=“20sp”

android:textColor="@color/colorBlack"

android:layout_width=“match_parent”

android:layout_height=“wrap_content” />

</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView

android:id="@+id/hot_search_rv"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

app:layout_behavior="@string/appbar_scrolling_view_behavior"

</android.support.v7.widget.RecyclerView>

</android.support.design.widget.CoordinatorLayout>

  • java file :

package openeyes.dr.openeyes.view.activity;

public class SearchActivity extends AppCompatActivity {

@BindView(R.id.search_editext)

SearchEditText searchEditText;

@BindView(R.id.cancle_main)

TextView cancleMain;

@BindView(R.id.history_fl)

FrameLayout hintLayout;

@BindView(R.id.delete_history)

TextView deleteHistory;

@BindView(R.id.search_history_rv)

RecyclerView recyclerSearch;

@BindView(R.id.hot_search_rv)

RecyclerView recyclerHot;

private String [] hotKeyWord = {“ food ”,“ travel ”,“ Life tips ”,“ Bodybuilding ”,“ automobile ”,“ advertisement ”,“ Animation ”,

“ Creative inspiration ”,“ Current garbled code ”,“ One ”,“ Eclipse ”,“ Visual knowledge TV”};

private List searchHistories;

private List hotKeyWords = new ArrayList<>();;

private SearchRecyclerAdapter adapter;

private SearchDB db;

private SearchRecyclerAdapter adapter1;

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_search);

ButterKnife.bind(this);

initData();

setListener();

}

private void initData() {

db = new SearchDB();

hotKeyWords.clear();

for (String keyWord:hotKeyWord){

hotKeyWords.add(new SearchHistory(keyWord));

}

LinearLayoutManager manager = new LinearLayoutManager(this);

manager.setOrientation(LinearLayout.VERTICAL);

recyclerHot.setLayoutManager(manager);

adapter = new SearchRecyclerAdapter(hotKeyWords);

recyclerHot.setAdapter(adapter);

recyclerHot.setItemAnimator(new DefaultItemAnimator());

searchHistories = db.loadSearchHistoryAll();

if (searchHistories==null||searchHistories.size()==0){

hintLayout.setVisibility(View.GONE);

recyclerSearch.setVisibility(View.GONE);

}else {

hintLayout.setVisibility(View.VISIBLE);

Collections.reverse(searchHistories);

LinearLayoutManager manager1 = new LinearLayoutManager(this);

manager.setOrientation(LinearLayout.VERTICAL);

recyclerSearch.setLayoutManager(manager1);

adapter1 = new SearchRecyclerAdapter(searchHistories);

recyclerSearch.setAdapter(adapter1);

recyclerSearch.setItemAnimator(new DefaultItemAnimator());// Add default animation

adapter1.setOnItemClickListener(new SearchRecyclerAdapter.OnItemClickListener() {

@Override

public void onItemClick(View itemview, SearchRecyclerAdapter.MyViewHolder childview, int position) {

Intent intent = new Intent(SearchActivity.this,SearchResultActivity.class);

Bundle bundle = new Bundle();

bundle.putString(“keyWord”,searchHistories.get(position).getKeyWord());

intent.putExtras(bundle);

startActivity(intent);

}

});

}

}

private void setListener() {

searchEditText.setOnKeyListener(new View.OnKeyListener() {

@Override

public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {

if (keyCode==KeyEvent.KEYCODE_ENTER&&keyEvent.getAction()==KeyEvent.ACTION_DOWN){

copyright notice
author[m0_ sixty-four million six hundred and four thousand six hundre],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041626592759.html

Random recommended