一.布局样式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro />
</RelativeLayout>
</LinearLayout>
这个我布局我手机没问题就没注意,以为没有问题,后面部分手机会有很大的空白区域,滑动控件冲突了。以后遇到两个滑动控件嵌套都会有问题,必须自定义一个滑动控件,我认为最好是自定义嵌套的内部滑动控件,感觉比较简单。
二。自定义WebView
public class MyWebView extends WebView {
public MyWebView(Context context) {
super(context);
}
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
主要复写onMeasure()方法 重新计算一下高度即可,然后在修改完的时候发现会滚动到WebView的位置
继续修改贴上部分代码
public class EveryDayDetailActivity extends BaseActivity implements OnClickListener {
@Override
protected void initView() {
// TODO Auto-generated method stub
setContentView(R.layout.everyday_detail);
jg_rl_parent = (RelativeLayout) findViewById(R.id.jg_rl_parent);
ll_pb = (LinearLayout) findViewById(R.id.ll_pb);
back = (TextView) findViewById(R.id.everyday_back);//返回
listView = (Listview) findViewById(R.id.everyday_listview);
/** 有视频则显示视频播放 */
webView = (WebView) findViewById(R.id.everyday_webview);
title = (TextView) findViewById(R.id.everyday_title);
imageView = (SimpleDraweeView) findViewById(R.id.everyday_background);
/**
* 改为自定义控件自动滚动到了WebView,添加焦点不让滚动到WebView
* */
imageView.setFocusable(true);
imageView.requestFocus();
imageView.setFocusableInTouchMode(true);
ll_knowledge_head_bottom = (LinearLayout) findViewById(R.id.ll_knowledge_head_bottom);
mMyTxVideo = (MyTxVideo) findViewById(R.id.my_tx_video);//视频空间
tv_middle_play = (TextView) findViewById(R.id.tv_middle_play);//播放按钮控件
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);//加载转圈
popshare = getLayoutInflater().inflate(R.layout.popupwindow_share, null);//分享弹框布局
/** 商品和拍卖 */
ll_goods = (LinearLayout)findViewById(R.id.ll_goods);//商品和拍卖父控件
ll_collect_image_container = (LinearLayout)findViewById(R.id.ll_collect_image_container);//商品和拍卖控件
/** 底部 */
views = (TextView) findViewById(R.id.everyday_views);
share = (LinearLayout) findViewById(R.id.everyday_share);
pinglun = (LinearLayout) findViewById(R.id.everyday_pinglun);
everyday_comment = (TextView) findViewById(R.id.everyday_comment);
iv_collect = (ImageView) findViewById(R.id.iv_collect);
ll_collect = (LinearLayout) findViewById(R.id.ll_collect);
}
}
把焦点给上面的任何一个控件就可以了
/**
* 改为自定义控件自动滚动到了WebView,添加焦点不让滚动到WebView
* */
imageView.setFocusable(true);
imageView.requestFocus();
imageView.setFocusableInTouchMode(true);