I am loading a webview with a close button and a slide button. When I clic
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF"
android:layout_marginRight="25dip"
android:layout_marginTop="25dip"
android:layout_marginLeft="25dip"
android:layout_marginBottom="25dip" >
<WebView
android:id="@+id/webac_larger"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</WebView>
<ImageView android:id="@+id/close_btn"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/close_button"
android:layout_marginTop="-3dip"
android:layout_marginRight="0dip"
/>
<ImageButton
android:id="@+id/slidebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/close_btn"
android:src="@drawable/arrowleft" />
I want to resize webview on click of a button.
final ImageButton button1 = (ImageButton) findViewById(R.id.slidebutton);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("MultiWeb", "I have clicked the button");
RelativeLayout params = ((RelativeLayout )button1.getParent());
params.setLayoutParams(new RelativeLayout.LayoutParams(100, 100));
}
});
I am getting this error. I am using relatice layout and why error says something about frame layout ?
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
As stated in the Android Layouts API Guide, each type of
ViewGrouphas its ownLayoutParamsclass that define the size and position for childViews.Instead of creating a brand new instance of one of the
LayoutParamsclasses and risking aClassCastException, you can callgetLayoutParams()on your view to get the current parameter object, modify it as you wish, and callsetLayoutParams()to apply the updated parameters.