At first you're getting an exception, because if you look into search_view.xml located in
\Android\android-sdk\platforms\android-18\data\res\layout\
You'll find out that SearchView is basically simple LinearLayout merging several widgets together. That's why you are getting class cast exception. Instead of
android.view.ViewGroup.LayoutParams params = searchview.getLayoutParams();
use
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) searchview.getLayoutParams();
or just import correct class and then you can simply use this
import android.widget.LinearLayout.LayoutParams;
...
LayoutParams params = (LayoutParams) searchview.getLayoutParams();
than you can use LayoutParams without any prefix.
But I don't think that setting LayoutParams
to wrap content will help. I would wrap your SearchView
and ImageButton
to RelativeLayout
, where you could specify view position relative to the other views. Then simply set SearchView
width to fill parent, so it could fill remaining space.