Skip to content

Commit 291af72

Browse files
author
Wu Jing
committed
fix header size bugs
1 parent 1d02c16 commit 291af72

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

app/src/main/java/com/race604/flyrefresh/sample/MainActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class MainActivity extends AppCompatActivity implements FlyRefreshLayout.
3939

4040
private ArrayList<ItemData> mDataSet = new ArrayList<>();
4141
private Handler mHandler = new Handler();
42+
private LinearLayoutManager mLayoutManager;
4243

4344
@Override
4445
protected void onCreate(Bundle savedInstanceState) {
@@ -56,7 +57,8 @@ protected void onCreate(Bundle savedInstanceState) {
5657

5758
mListView = (RecyclerView) findViewById(R.id.list);
5859

59-
mListView.setLayoutManager(new LinearLayoutManager(this));
60+
mLayoutManager = new LinearLayoutManager(this);
61+
mListView.setLayoutManager(mLayoutManager);
6062
mAdapter = new ItemAdapter(this);
6163

6264
mListView.setAdapter(mAdapter);
@@ -74,6 +76,7 @@ private void addItemData() {
7476
ItemData itemData = new ItemData(Color.parseColor("#FFC970"), R.mipmap.ic_smartphone_white_24dp, "Magic Cube Show", new Date());
7577
mDataSet.add(0, itemData);
7678
mAdapter.notifyItemInserted(0);
79+
mLayoutManager.scrollToPosition(0);
7780
}
7881

7982
@Override

library/src/main/java/com/race604/flyrefresh/FlyRefreshLayout.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import android.view.ViewGroup;
1111
import android.view.animation.AccelerateInterpolator;
1212
import android.view.animation.DecelerateInterpolator;
13-
import android.widget.ImageView;
1413

15-
import com.race604.flyrefresh.internal.MountainSceneDrawable;
1614
import com.race604.flyrefresh.internal.MountanScenceView;
1715
import com.race604.flyrefresh.internal.SimpleAnimatorListener;
1816
import com.race604.utils.UIUtils;
@@ -46,8 +44,6 @@ public FlyRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr, i
4644
}
4745

4846
private void init(Context context) {
49-
int maxHeight = UIUtils.dpToPx(300);
50-
setHeaderSize((int) (maxHeight * 0.8f), maxHeight, UIUtils.dpToPx(48));
5147
MountanScenceView headerView = new MountanScenceView(getContext());
5248
LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mHeaderController.getMaxHeight());
5349
setHeaderView(headerView, lp);
@@ -56,7 +52,11 @@ private void init(Context context) {
5652
@Override
5753
protected void onFinishInflate() {
5854
super.onFinishInflate();
59-
setActionDrawable(getResources().getDrawable(R.mipmap.ic_send));
55+
56+
// Set default action icon if user not override
57+
if (getIconView() == null) {
58+
setActionDrawable(getResources().getDrawable(R.mipmap.ic_send));
59+
}
6060
}
6161

6262
@Override

library/src/main/java/com/race604/flyrefresh/PullHeaderLayout.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public class PullHeaderLayout extends ViewGroup {
3737

3838
final static int ACTION_BUTTON_CENTER = UIUtils.dpToPx(40);
3939
final static int ACTION_ICON_SIZE = UIUtils.dpToPx(32);
40-
private final static int DEFAULT_EXPAND = UIUtils.dpToPx(40);
41-
private final static int DEFAULT_HEIGHT = 0;
40+
private final static int DEFAULT_EXPAND = UIUtils.dpToPx(300);
41+
private final static int DEFAULT_HEIGHT = UIUtils.dpToPx(240);
42+
private final static int DEFAULT_SHRINK = UIUtils.dpToPx(48);
4243

4344
private int mHeaderId = 0;
4445
private int mContentId = 0;
@@ -92,7 +93,7 @@ public PullHeaderLayout(Context context, AttributeSet attrs, int defStyleAttr, i
9293
private void init(Context context, AttributeSet attrs) {
9394
int headerHeight = DEFAULT_HEIGHT;
9495
int headerExpandHeight = DEFAULT_EXPAND;
95-
int headerShrinkHeight = DEFAULT_HEIGHT;
96+
int headerShrinkHeight = DEFAULT_SHRINK;
9697

9798
if (attrs != null) {
9899
TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.PullHeaderLayout);
@@ -101,7 +102,7 @@ private void init(Context context, AttributeSet attrs) {
101102
headerExpandHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_expand_height,
102103
DEFAULT_EXPAND);
103104
headerShrinkHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_shrink_height,
104-
DEFAULT_HEIGHT);
105+
DEFAULT_SHRINK);
105106

106107
mHeaderId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_header, mHeaderId);
107108
mContentId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_content, mContentId);

0 commit comments

Comments
 (0)