-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
update-app/src/main/java/com/vector/update_app/view/AutoScrollView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.vector.update_app.view; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.util.DisplayMetrics; | ||
import android.view.Display; | ||
import android.widget.ScrollView; | ||
|
||
/** | ||
* Created by Vector | ||
* on 2017/7/13 0013. | ||
*/ | ||
|
||
public class AutoScrollView extends ScrollView { | ||
private Context mContext; | ||
|
||
public AutoScrollView(Context context) { | ||
super(context); | ||
init(context); | ||
} | ||
|
||
public AutoScrollView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
init(context); | ||
|
||
} | ||
|
||
public AutoScrollView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
init(context); | ||
} | ||
|
||
private void init(Context context) { | ||
mContext = context; | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
try { | ||
//最大高度显示为屏幕内容高度的一半 | ||
Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay(); | ||
DisplayMetrics d = new DisplayMetrics(); | ||
display.getMetrics(d); | ||
//此处是关键,设置控件高度不能超过屏幕高度一半(在此替换成自己需要的高度) | ||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(d.heightPixels / 3, MeasureSpec.AT_MOST); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
//重新计算控件高、宽 | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters