我在一个版面上有2个网页浏览量。 我想要触摸,触摸的视图会变得更大(更宽)而牺牲另一个视图,我该怎么做?
谢谢!
答案 0 :(得分:1)
子类WebView:
public class MyWebView extends WebView{
private MyActivity mActivity;
//Call this on each webview in activity's onCreate after
//instantiating the web views. i.e. after setContentView()
//and assigning it to a variable with findViewById() or
//after programmatically creating the web view.
public setActivity(MyActivity activity){
mActivity = activity;
}
@Override
public boolean onTouchEvent(MotionEvent event){
if (event.getAction()==ACTION_POINTER_DOWN && mActivity!=null){
mActivity.onWebviewTouched(self);
}
super.onTouchEvent(event);
}
}
在你的活动中:
public void onWebviewTouched(MyWebView webView) {
if (webView == mWebviewLeft){
//grow left webview if it isn't already grown, and shrink right webview.
} else if (webView == mWebviewRight) {
//grow right webview if it isn't already grown, and shrink left webview.
}
}
使用Animation类及其子类可以平滑地修改视图的宽度。如果使用LinearLayout,您可以将一个视图的布局权重设置为常量值,并简单地为另一个视图的布局权重设置动画,使其大于或小于该常量值。
如果您只是想要即时更改,只需使用LayoutParams直接设置视图宽度。