项目运行,先将上面A部分的透明度设为0,整体看上去就是B那一坨。
页面进行滑动,A慢慢展现出来,B就被遮挡住,滑出手机屏幕。 此效果 只适用于版本大于23的安卓手机。(xml根布局采用相对布局)
LinearLayout linearLayout = findViewById(R.id.rl_shangla);
linearLayout.setAlpha(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView nestedScrollView, int i, int i1, int i2, int i3) {
if (i1 <= 150) {
float alpha = (float) (new Float(i1) / 150);
if (alpha >= 1) {
alpha = 1;
}
linearLayout.setAlpha(alpha);
} else {
linearLayout.setAlpha(1);
}
}
});
}
界面如下如下:
此操作只适用于一些简单操作,复杂的可以采用折叠布局进行实现;
附上xml文件;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/sroc"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="31dp"
android:background="#4277BF" />
<!--头像-->
<RelativeLayout
android:id="@+id/rl_tou"
android:layout_width="match_parent"
android:layout_height="86dp"
android:background="#4277BF">
<ImageView
android:id="@+id/iv_touxiang"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_centerVertical="true"
android:layout_marginLeft="9dp"
android:layout_toRightOf="@+id/iv_touxiang"
android:orientation="vertical">
<TextView
style="Bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/timoxi"
android:textColor="#ffffffff"
android:textSize="17sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:background="@drawable/bg_personal">
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="center"
android:src="@mipmap/zl" />
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="3dp"
android:paddingRight="13dp"
android:paddingBottom="3dp"
android:text="项目经理 I 成都聪蛙科技有限公司"
android:textColor="#ffffffff"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="4dp"
android:layout_marginRight="15dp"
android:orientation="horizontal">
<ImageView
android:layout_width="14dp"
android:layout_height="13dp"
android:layout_gravity="center"
android:src="@mipmap/bianji2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:text="完善名片"
android:textColor="#FFFFFF"
android:textSize="13dp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--我的工具-->
<LinearLayout
android:layout_width="330dp"
android:layout_height="373dp"
android:layout_gravity="center"
android:layout_marginTop="14dp"
android:background="@drawable/bg_gongju"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="43dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="14dp"
android:text="@string/target_string"
android:textColor="#ff050505"
android:textSize="15dp" />
</LinearLayout>
<GridView
android:nestedScrollingEnabled="false"
android:id="@+id/GridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:columnWidth="110dp"
android:horizontalSpacing="2dp"
android:numColumns="3"
android:scrollbars="none"
android:verticalSpacing="1dp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="330dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/rl_shangla"
android:layout_width="match_parent"
android:layout_height="42dp"
android:background="#4277BF"
android:orientation="horizontal">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="6dp"
android:text="@string/timoxi"
android:textColor="#ffffffff"
android:textSize="17dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:background="@drawable/bg_personal">
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="center"
android:src="@mipmap/zl" />
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="3dp"
android:paddingRight="13dp"
android:paddingBottom="3dp"
android:text="项目经理 I 公司"
android:textColor="#ffffffff"
android:textSize="12dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<ImageView
android:layout_width="17dp"
android:layout_height="19dp"
android:layout_gravity="center"
android:layout_marginRight="13dp"
android:src="@mipmap/shezhi" />
</LinearLayout>
</RelativeLayout>