近期項目比較忙纯续,今日才有時間給大家分享android的一些實用的知識~
what is getLocationInWindow
android中一種獲取view坐標(biāo)的方法仁讨,獲取在當(dāng)前窗口內(nèi)的絕對坐標(biāo)羽莺。
int[] location = new int[2] ;
view.getLocationInWindow(location);
解釋:
location[0] -----> x坐標(biāo)
location[1] -----> y坐標(biāo)
對比
android中獲取view坐標(biāo)的方法有兩種:
- getLocationInWindow
- 獲取在當(dāng)前窗口內(nèi)的絕對坐標(biāo)
- getLocationOnScreen
- 獲取在整個屏幕內(nèi)的絕對坐標(biāo)
- 從屏幕頂端算起,包括了通知欄的高度
1132780-253900d649118aa0.jpg
踩過的坑
1132780-4e0c4064e76528b6.jpg
在onCreate里面調(diào)用洞豁,會得到location[0]和location[1]的值均為空盐固,這是因為UI控件還沒加載好的原因。所以我們可以使用view.post(runnable)方法去獲取或者在onWindowFocusChanged(boolean hasFocus)方法中獲取丈挟。
使用案例
1132780-2d7d1306d1b86b65.jpg
案例效果圖如下:
LocationInWindon.gif
核心代碼分析
首先我們需要保存頂部Tab滑動各item寬度坐標(biāo)闰挡,代碼如下:
/**
* 保存癥狀詳情頂部tab橫向?qū)挾茸鴺?biāo)
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param
* @return
*/
private void saveSymptomDetailHorizontalWidth() {
int[] location = new int[2];
for (int i = 0; i < symptomDetailContainerLy.getChildCount(); i++) {
getSingleNavigation(i).getLocationInWindow(location);
symptomDetailHorizontalWidth[i] = location[0];
}
}
然后保存癥狀詳情滑動高度坐標(biāo),代碼如下:
/**
* 保存癥狀詳情滑動高度坐標(biāo)
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param
* @return
*/
private void savesymtomDetailScvHeight() {
// 癥狀詳情
final int[] symptomModuleLoc = new int[2];
final int[] symptomLocation = new int[2];
// 癥狀模塊
symptomModuleLy.post(new Runnable() {
@Override
public void run() {
symptomModuleLy.getLocationInWindow(symptomModuleLoc);
symtomDetailScvHeight[0] = 0;
}
});
// 病因模塊
pathogenyModuleLy.post(new Runnable() {
@Override
public void run() {
pathogenyModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[1] = symptomLocation[1] - symptomModuleLoc[1];
}
});
// 檢查模塊
checkoutModuleLy.post(new Runnable() {
@Override
public void run() {
checkoutModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[2] = symptomLocation[1] - symptomModuleLoc[1];
}
});
// 診斷模塊
diagnoseModuleLy.post(new Runnable() {
@Override
public void run() {
diagnoseModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[3] = symptomLocation[1] -symptomModuleLoc[1];
}
});
// 預(yù)防模塊
preventModuleLy.post(new Runnable() {
@Override
public void run() {
preventModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[4] = symptomLocation[1] - symptomModuleLoc[1];
}
});
foodTreatModuleLy.post(new Runnable() {
@Override
public void run() {
// 食療模塊
foodTreatModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[5] = symptomLocation[1] - symptomModuleLoc[1];
}
});
}
接著設(shè)置滑動監(jiān)聽礁哄、點擊頂部Tab事件长酗,代碼如下:
/**
* 癥狀詳情頂部tab橫向監(jiān)聽
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param
* @return
*/
class OnSymtomHorizontalScClickedListener implements View.OnClickListener {
@Override
public void onClick(View view) {
isTopClick = true;
setSymtomHorizontalCurrentPostion(view, true, 0, 0);
}
}
@Override
protected void registerListener() {
// 退出當(dāng)前頁面
findViewById(R.id.iv_actionbar_back).setOnClickListener(this);
// 設(shè)置滑動監(jiān)聽
if (symptomDetailScv != null)
symptomDetailScv.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
@Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
int oldx, int oldy, int oritention) {
if (isTopClick) {
isTopClick = false;
return;
}
// 癥狀詳情
// 如果癥狀詳情頂部tab橫向?qū)挾茸鴺?biāo)或者癥狀詳情滑動高度坐標(biāo)則返回
if (symtomDetailScvHeight == null || symptomDetailHorizontalWidth == null)
return;
if (y >= symtomDetailScvHeight[0] && y < symtomDetailScvHeight[1]) {
// 癥狀
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(0),
false, symptomDetailHorizontalWidth[0], y);
} else if (y >= symtomDetailScvHeight[1] && y < symtomDetailScvHeight[2]) {
// 病因
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(1),
false, symptomDetailHorizontalWidth[1], y);
} else if (y >= symtomDetailScvHeight[2] && y < symtomDetailScvHeight[3]) {
// 檢查
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(2),
false, symptomDetailHorizontalWidth[2], y);
} else if (y >= symtomDetailScvHeight[3] && y < symtomDetailScvHeight[4]) {
// 診斷
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(3),
false, symptomDetailHorizontalWidth[3], y);
} else if (y >= symtomDetailScvHeight[4] && y < symtomDetailScvHeight[5]) {
// 預(yù)防
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(4),
false, symptomDetailHorizontalWidth[4], y);
} else if (y >= symtomDetailScvHeight[5]) {
// 食療
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(5),
false, symptomDetailHorizontalWidth[5], y);
}
}
});
}
最后設(shè)置頂部Tab位置,代碼如下:
/**
* 設(shè)置癥狀詳情頂部tab位置
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param view
* @param fromClick 是否點擊
* @param x x坐標(biāo)
* @param y y坐標(biāo)
* @return
*/
public void setSymtomHorizontalCurrentPostion(View view, boolean fromClick, int x, int y){
// 如果不是點擊事件并橫向滑動控件不為空則滑動到指定坐標(biāo)
if (!fromClick && symptomDetailHscv != null) {
symptomDetailHscv.scrollTo(x, y);
}
if (view == null){
return;
}
if (view.getTag() == null)
return;
// 獲取當(dāng)前位置
int position = (Integer) view.getTag();
// 如果當(dāng)前位置非上次位置
if (lastPosition != position){
// 如果頂部tab動態(tài)加載容器為空桐绒,則重新實例化
if (symptomDetailContainerLy == null) {
// 頂部tab動態(tài)加載容器
symptomDetailContainerLy = (LinearLayout) findViewById(R.id.ly_symptom_detail_container);
}
// 設(shè)置上次位置藍色下滑線不可見
getNavigationImageView(lastPosition).setVisibility(View.INVISIBLE);
// 設(shè)置上次位置字體顏色為黑色
getNavigationTextView(lastPosition).setTextColor(
getResources().getColor(R.color.text_color_black));
// 設(shè)置當(dāng)前位置藍色下劃線可見
getNavigationImageView(position).setVisibility(View.VISIBLE);
// 設(shè)置當(dāng)前位置字體顏色為藍色
getNavigationTextView(position).setTextColor(
getResources().getColor(R.color.title_color));
}
lastPosition = position;
if (symptomDetailScv != null && fromClick) {
symptomDetailScv.scrollTo(0, symtomDetailScvHeight[position]);
}
}
癥狀詳情頁面完整代碼如下:
package cn.jianke.getlocationinwindowdemo.module.activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import cn.jianke.getlocationinwindowdemo.R;
import cn.jianke.getlocationinwindowdemo.httprequest.ApiCallback;
import cn.jianke.getlocationinwindowdemo.httprequest.api.ApiSymptomDetail;
import cn.jianke.getlocationinwindowdemo.httprequest.httpresponse.SymptomDetailResponse;
import cn.jianke.getlocationinwindowdemo.module.util.HTMLSpirit;
import cn.jianke.getlocationinwindowdemo.module.util.StringUtil;
import cn.jianke.getlocationinwindowdemo.module.util.Unicode2String;
import cn.jianke.getlocationinwindowdemo.module.widget.ObservableScrollView;
import static cn.jianke.getlocationinwindowdemo.module.activity.MainActivity.SYMPTOM_ID;
/**
* @className: SymptomDetailActivity
* @classDescription: 癥狀詳情
* @author: leibing
* @createTime: 2016/10/29
*/
public class SymptomDetailActivity extends BaseActivity implements View.OnClickListener{
// 癥狀id
private String id = "";
// 頂部橫向滑動控件
private HorizontalScrollView symptomDetailHscv;
// 頂部tab動態(tài)加載容器
private LinearLayout symptomDetailContainerLy;
// 滑動控件
private ObservableScrollView symptomDetailScv;
// 癥狀模塊
private LinearLayout symptomModuleLy;
// 癥狀標(biāo)題
private TextView symptomTitleTv;
// 癥狀內(nèi)容
private TextView symptomContentTv;
// 病因模塊
private LinearLayout pathogenyModuleLy;
// 病因內(nèi)容
private TextView pathogenyContentTv;
// 檢查模塊
private LinearLayout checkoutModuleLy;
// 檢查內(nèi)容
private TextView checkoutContentTv;
// 診斷模塊
private LinearLayout diagnoseModuleLy;
// 診斷內(nèi)容
private TextView diagnoseContentTv;
// 預(yù)防模塊
private LinearLayout preventModuleLy;
// 預(yù)防內(nèi)容
private TextView preventContentTv;
// 食療模塊
private LinearLayout foodTreatModuleLy;
// 食療內(nèi)容
private TextView foodTreatContentTv;
// 癥狀詳情數(shù)據(jù)
private SymptomDetailResponse symptomDetailResponse;
// 癥狀詳情頂部tab橫向?qū)挾茸鴺?biāo)
private final int[] symptomDetailHorizontalWidth = new int[6];
// 癥狀詳情滑動高度坐標(biāo)
private final int[] symtomDetailScvHeight = new int[6];
// 是否頂部點擊事件
private boolean isTopClick = false;
// 上次點擊點頂部tab item的位置
private int lastPosition = 0;
// 癥狀詳情api
private ApiSymptomDetail mApiSymptomDetail;
@Override
protected void setContentView() {
// 指定布局
setContentView(R.layout.activity_symptom_detail);
}
@Override
protected void initView() {
// 滑動控件
symptomDetailScv = (ObservableScrollView) findViewById(R.id.scv_symptom_detail);
// 頂部橫向滑動控件
symptomDetailHscv = (HorizontalScrollView) findViewById(R.id.hscv_symptom_detail);
// 頂部tab動態(tài)加載容器
symptomDetailContainerLy = (LinearLayout) findViewById(R.id.ly_symptom_detail_container);
// 癥狀模塊
symptomModuleLy = (LinearLayout) findViewById(R.id.ly_symptom_module);
// 癥狀標(biāo)題
symptomTitleTv = (TextView) findViewById(R.id.tv_symptom_title);
// 癥狀內(nèi)容
symptomContentTv = (TextView) findViewById(R.id.tv_symptom_content);
// 病因模塊
pathogenyModuleLy = (LinearLayout) findViewById(R.id.ly_pathogeny_module);
// 病因內(nèi)容
pathogenyContentTv = (TextView) findViewById(R.id.tv_pathogeny_content);
// 檢查模塊
checkoutModuleLy = (LinearLayout) findViewById(R.id.ly_checkout_module);
// 檢查內(nèi)容
checkoutContentTv = (TextView) findViewById(R.id.tv_checkout_content);
// 診斷模塊
diagnoseModuleLy = (LinearLayout) findViewById(R.id.ly_diagnose_module);
// 診斷內(nèi)容
diagnoseContentTv = (TextView) findViewById(R.id.tv_diagnose_content);
// 預(yù)防模塊
preventModuleLy = (LinearLayout) findViewById(R.id.ly_prevent_module);
// 預(yù)防內(nèi)容
preventContentTv = (TextView) findViewById(R.id.tv_prevent_content);
// 食療模塊
foodTreatModuleLy = (LinearLayout) findViewById(R.id.ly_food_treat_module);
// 食療內(nèi)容
foodTreatContentTv = (TextView) findViewById(R.id.tv_food_treat_content);
// 獲取意圖傳值
getIntentData();
// 初始化癥狀詳情api
mApiSymptomDetail = new ApiSymptomDetail();
// 初始化癥狀詳情頂部tab
initSymptomDetailHorizontalTab();
}
@Override
protected void registerListener() {
// 退出當(dāng)前頁面
findViewById(R.id.iv_actionbar_back).setOnClickListener(this);
// 設(shè)置滑動監(jiān)聽
if (symptomDetailScv != null)
symptomDetailScv.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
@Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
int oldx, int oldy, int oritention) {
if (isTopClick) {
isTopClick = false;
return;
}
// 癥狀詳情
// 如果癥狀詳情頂部tab橫向?qū)挾茸鴺?biāo)或者癥狀詳情滑動高度坐標(biāo)則返回
if (symtomDetailScvHeight == null || symptomDetailHorizontalWidth == null)
return;
if (y >= symtomDetailScvHeight[0] && y < symtomDetailScvHeight[1]) {
// 癥狀
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(0),
false, symptomDetailHorizontalWidth[0], y);
} else if (y >= symtomDetailScvHeight[1] && y < symtomDetailScvHeight[2]) {
// 病因
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(1),
false, symptomDetailHorizontalWidth[1], y);
} else if (y >= symtomDetailScvHeight[2] && y < symtomDetailScvHeight[3]) {
// 檢查
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(2),
false, symptomDetailHorizontalWidth[2], y);
} else if (y >= symtomDetailScvHeight[3] && y < symtomDetailScvHeight[4]) {
// 診斷
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(3),
false, symptomDetailHorizontalWidth[3], y);
} else if (y >= symtomDetailScvHeight[4] && y < symtomDetailScvHeight[5]) {
// 預(yù)防
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(4),
false, symptomDetailHorizontalWidth[4], y);
} else if (y >= symtomDetailScvHeight[5]) {
// 食療
setSymtomHorizontalCurrentPostion(symptomDetailContainerLy.getChildAt(5),
false, symptomDetailHorizontalWidth[5], y);
}
}
});
}
@Override
protected void getData() {
if (mApiSymptomDetail != null){
// 請求數(shù)據(jù)
mApiSymptomDetail.getSymptomDetail(id, SymptomDetailActivity.this,
new ApiCallback<SymptomDetailResponse>() {
@Override
public void onSuccess(SymptomDetailResponse response) {
// 更新UI
updateSymptomUI(response);
}
@Override
public void onError(String err_msg) {
Toast.makeText(SymptomDetailActivity.this,
err_msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure() {
Toast.makeText(SymptomDetailActivity.this,
"網(wǎng)絡(luò)不給力", Toast.LENGTH_SHORT).show();
}
});
}
}
/**
* 更新癥狀詳情UI
* @author leibing
* @createTime 2016/10/08
* @lastModify 2016/10/08
* @param response 癥狀詳情數(shù)據(jù)
* @return
*/
private void updateSymptomUI(SymptomDetailResponse response) {
// 更新癥狀詳情數(shù)據(jù)
symptomDetailResponse = response;
// 癥狀
if (StringUtil.isNotEmpty(symptomDetailResponse.namecn)
&& StringUtil.isNotEmpty(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.summarize)))){
// 癥狀標(biāo)題
symptomTitleTv.setText(symptomDetailResponse.namecn);
// 癥狀內(nèi)容
symptomContentTv.setText(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.summarize)));
}
if (StringUtil.isNotEmpty(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.pathogeny)))){
// 病因內(nèi)容
pathogenyContentTv.setText(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.pathogeny)));
}
if (StringUtil.isNotEmpty(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.diagnoses)))){
// 檢查內(nèi)容
checkoutContentTv.setText(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.diagnoses)));
}
if (StringUtil.isNotEmpty(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.differential)))){
// 診斷內(nèi)容
diagnoseContentTv.setText(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.differential)));
}
if (StringUtil.isNotEmpty(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.prevent)))){
// 預(yù)防內(nèi)容
preventContentTv.setText(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.prevent)));
}
if (StringUtil.isNotEmpty(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.foodtreat)))){
// 食療內(nèi)容
foodTreatContentTv.setText(HTMLSpirit.removeHtmlTag(
Unicode2String.decodeUnicode(symptomDetailResponse.foodtreat)));
}
// 設(shè)置高度和寬度
savesymtomDetailScvHeight();
saveSymptomDetailHorizontalWidth();
}
/**
* 獲取意圖傳值
* @author leibing
* @createTime 2016/10/29
* @lastModify 2016/10/29
* @param
* @return
*/
private void getIntentData() {
// 獲取意圖傳值
Bundle bundle = getIntent().getExtras();
if (bundle != null){
// 癥狀id
id = bundle.getString(SYMPTOM_ID, "");
}
}
/**
* 初始化癥狀詳情頂部tab
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param
* @return
*/
private void initSymptomDetailHorizontalTab() {
// 獲取頂部滑動item名稱
String[] array = getResources().getStringArray(
R.array.symptom_detail_navigation_name);
// 初始化監(jiān)聽
OnSymtomHorizontalScClickedListener listener = new OnSymtomHorizontalScClickedListener();
for (int i = 0; i < array.length; i++) {
// 獲取子view
View childView = LayoutInflater.from(SymptomDetailActivity.this).inflate(
R.layout.check_details_single_navigation_model, null);
// 實例化子view控件
TextView titleTv = (TextView)
childView.findViewById(R.id.check_details_navigation_textView);
// 給子view控件初始化值
titleTv.setText(array[i]);
// 子view設(shè)置tag
childView.setTag(i);
// 子view設(shè)置監(jiān)聽
childView.setOnClickListener(listener);
// 子view添加到父容器
symptomDetailContainerLy.addView(childView);
}
// 默認為選中第一個
getNavigationImageView(0).setVisibility(View.VISIBLE);
getNavigationTextView(0).setTextColor(
getResources().getColor(R.color.title_color));
}
/**
* 設(shè)置癥狀詳情頂部tab位置
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param view
* @param fromClick 是否點擊
* @param x x坐標(biāo)
* @param y y坐標(biāo)
* @return
*/
public void setSymtomHorizontalCurrentPostion(View view, boolean fromClick, int x, int y){
// 如果不是點擊事件并橫向滑動控件不為空則滑動到指定坐標(biāo)
if (!fromClick && symptomDetailHscv != null) {
symptomDetailHscv.scrollTo(x, y);
}
if (view == null){
return;
}
if (view.getTag() == null)
return;
// 獲取當(dāng)前位置
int position = (Integer) view.getTag();
// 如果當(dāng)前位置非上次位置
if (lastPosition != position){
// 如果頂部tab動態(tài)加載容器為空夺脾,則重新實例化
if (symptomDetailContainerLy == null) {
// 頂部tab動態(tài)加載容器
symptomDetailContainerLy = (LinearLayout) findViewById(R.id.ly_symptom_detail_container);
}
// 設(shè)置上次位置藍色下滑線不可見
getNavigationImageView(lastPosition).setVisibility(View.INVISIBLE);
// 設(shè)置上次位置字體顏色為黑色
getNavigationTextView(lastPosition).setTextColor(
getResources().getColor(R.color.text_color_black));
// 設(shè)置當(dāng)前位置藍色下劃線可見
getNavigationImageView(position).setVisibility(View.VISIBLE);
// 設(shè)置當(dāng)前位置字體顏色為藍色
getNavigationTextView(position).setTextColor(
getResources().getColor(R.color.title_color));
}
lastPosition = position;
if (symptomDetailScv != null && fromClick) {
symptomDetailScv.scrollTo(0, symtomDetailScvHeight[position]);
}
}
/**
* 保存癥狀詳情頂部tab橫向?qū)挾茸鴺?biāo)
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param
* @return
*/
private void saveSymptomDetailHorizontalWidth() {
int[] location = new int[2];
for (int i = 0; i < symptomDetailContainerLy.getChildCount(); i++) {
getSingleNavigation(i).getLocationInWindow(location);
symptomDetailHorizontalWidth[i] = location[0];
}
}
/**
* 保存癥狀詳情滑動高度坐標(biāo)
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param
* @return
*/
private void savesymtomDetailScvHeight() {
// 癥狀詳情
final int[] symptomModuleLoc = new int[2];
final int[] symptomLocation = new int[2];
// 癥狀模塊
symptomModuleLy.post(new Runnable() {
@Override
public void run() {
symptomModuleLy.getLocationInWindow(symptomModuleLoc);
symtomDetailScvHeight[0] = 0;
}
});
// 病因模塊
pathogenyModuleLy.post(new Runnable() {
@Override
public void run() {
pathogenyModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[1] = symptomLocation[1] - symptomModuleLoc[1];
}
});
// 檢查模塊
checkoutModuleLy.post(new Runnable() {
@Override
public void run() {
checkoutModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[2] = symptomLocation[1] - symptomModuleLoc[1];
}
});
// 診斷模塊
diagnoseModuleLy.post(new Runnable() {
@Override
public void run() {
diagnoseModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[3] = symptomLocation[1] -symptomModuleLoc[1];
}
});
// 預(yù)防模塊
preventModuleLy.post(new Runnable() {
@Override
public void run() {
preventModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[4] = symptomLocation[1] - symptomModuleLoc[1];
}
});
foodTreatModuleLy.post(new Runnable() {
@Override
public void run() {
// 食療模塊
foodTreatModuleLy.getLocationInWindow(symptomLocation);
symtomDetailScvHeight[5] = symptomLocation[1] - symptomModuleLoc[1];
}
});
}
/**
* 癥狀詳情頂部tab橫向監(jiān)聽
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param
* @return
*/
class OnSymtomHorizontalScClickedListener implements View.OnClickListener {
@Override
public void onClick(View view) {
isTopClick = true;
setSymtomHorizontalCurrentPostion(view, true, 0, 0);
}
}
/**
* 根據(jù)索引獲取頂部滑動欄TextView實例
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param index 索引值
* @return
*/
private TextView getNavigationTextView(int index) {
if (symptomDetailContainerLy == null)
return null;
return (TextView) symptomDetailContainerLy.getChildAt(index).findViewById(
R.id.check_details_navigation_textView);
}
/**
* 根據(jù)索引獲取頂部滑動欄ImageView實例
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param index 索引值
* @return
*/
private ImageView getNavigationImageView(int index) {
if (symptomDetailContainerLy == null)
return null;
return (ImageView) symptomDetailContainerLy.getChildAt(index).findViewById(
R.id.check_details_navigation_imageView);
}
/**
* 根據(jù)索引獲取頂部滑動欄View實例
* @author leibing
* @createTime 2016/10/19
* @lastModify 2016/10/19
* @param index 索引值
* @return
*/
private View getSingleNavigation(int index) {
if (symptomDetailContainerLy == null)
return null;
return symptomDetailContainerLy.getChildAt(index);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.iv_actionbar_back:
// 退出當(dāng)前頁面
this.finish();
break;
default:
break;
}
}
}
項目地址:LocationInWindow
關(guān)于作者
- QQ:872721111
- Email:leibing1989@126.com
- Github:leibing@github
- 掘金:leibing@juejin
- 簡書:leibing@jianshu