Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.

Commit fc5ad3b

Browse files
committed
修复bug
1 parent 7954805 commit fc5ad3b

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

Diff for: toolbartest/src/main/java/com/lialzm/baidu/toolbartest/MainActivity.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
import android.widget.ArrayAdapter;
1010
import android.widget.ListView;
1111

12-
import com.lialzm.hyb.toolbartest.R;
13-
1412
import java.util.ArrayList;
1513
import java.util.List;
1614

1715
public class MainActivity extends AppCompatActivity {
1816

1917
private ListView lv;
20-
//测量值
2118
private float headerHeight;//顶部高度
2219

2320
@Override
@@ -39,6 +36,7 @@ protected void onCreate(Bundle savedInstanceState) {
3936
list.add("item" + i);
4037
}
4138
headerHeight = dp2px(200);
39+
4240
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, list));
4341
lv.setOnScrollListener(new AbsListView.OnScrollListener() {
4442
@Override
@@ -49,7 +47,7 @@ public void onScrollStateChanged(AbsListView view, int scrollState) {
4947
@Override
5048
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
5149
float scrollY = getScrollY(view);
52-
float offset = 1 - Math.max((headerHeight - scrollY) / headerHeight, 0f);
50+
float offset = 1 - Math.max((headerHeight - toolbar.getHeight() - scrollY) / (headerHeight - toolbar.getHeight()), 0f);
5351
toolbar.getBackground().setAlpha((int) (offset * 255));
5452

5553
}
@@ -63,7 +61,6 @@ private int dp2px(int dpVal) {
6361
}
6462

6563

66-
6764
/**
6865
* 得到ListView在Y轴上的偏移
6966
*/

Diff for: toolbartest/src/main/res/layout/activity_main.xml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
66
android:orientation="vertical">
77

8+
9+
<ListView
10+
android:id="@+id/lv"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent">
13+
14+
</ListView>
15+
816
<android.support.v7.widget.Toolbar
917
android:id="@+id/tb_main"
1018
android:layout_width="match_parent"
@@ -14,12 +22,4 @@
1422
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
1523

1624

17-
<ListView
18-
android:id="@+id/lv"
19-
android:layout_width="match_parent"
20-
android:layout_height="match_parent">
21-
22-
23-
</ListView>
24-
25-
</LinearLayout>
25+
</FrameLayout>

0 commit comments

Comments
 (0)