2

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
1
  • @user113215, why don't you make that an answer, so sam can accept it? :) Commented Sep 21, 2012 at 16:42

1 Answer 1

1

As stated in the Android Layouts API Guide, each type of ViewGroup has its own LayoutParams class that define the size and position for child Views.

Instead of creating a brand new instance of one of the LayoutParams classes and risking a ClassCastException, you can call getLayoutParams() on your view to get the current parameter object, modify it as you wish, and call setLayoutParams() to apply the updated parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.