theView.getLayoutParams().height = theNewHeight; theView.requestLayout(); :)
On Sun, Nov 8, 2009 at 3:45 AM, Wouter Vegter <wouterveg...@gmail.com> wrote: > Hello, > > I have defined a view with id "view01" in my xml layout file. I want > to change the height of this view on runtime. At first I wanted to do > it with a single click on the view, but I wasn't able to do that > properly, hence the onClickListener interface. After that i tried to > change the height of the view by hard coding. I didn't succeed. I have > searched quite a while on internet but so far I haven't found the > right solution. Can please someone help me out? > > My .java and .xml file are displayed below. > > Regards, > > Wouter > > > ***************.java file > package test2.main; > > > import android.app.Activity; > import android.os.Bundle; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.LinearLayout; > > > public class test2 extends Activity implements OnClickListener { > /** Called when the activity is first created. */ > �...@override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > View v1 = (View) findViewById(R.id.view01); > v1.setOnClickListener(this); > v1.setMinimumHeight(160); > LinearLayout ll = (LinearLayout) findViewById > (R.id.linearlayout); > ll.requestLayout(); > v1.requestLayout(); > > > } > > public void onClick(View arg0) { > if (arg0.getMeasuredHeight() == 80) > { > arg0.setMinimumHeight(160); > } else > { > arg0.setMinimumHeight(80); > } > arg0.requestLayout(); > } > } > > > **********.xml file > <?xml version="1.0" encoding="utf-8"?> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > android" android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" android:id="@+id/linearlayout"> > <TableLayout > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:stretchColumns="0" xmlns:android="http:// > schemas.android.com/apk/res/android"> > <TableRow> > <View > android:layout_height="80px" > android:background="#884400" /> > <TextView android:text="#884400" > android:paddingLeft="4px" > android:layout_gravity="center_vertical" /> > </TableRow> > <TableRow> > <View > android:layout_height="80px" > android:background="#aa8844" android:id="@+id/view01"/> > <TextView android:text="#aa8844" > android:paddingLeft="4px" > android:layout_gravity="center_vertical" /> > </TableRow> > </TableLayout> > </LinearLayout> > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en