Reputation: 6983
I'm trying to get the width of the screen and then change the width of the button. I'm using setWidth, and the width is not changing (I set it to a small numer, 30, so I could tell if the size change. code mBut = (Button)findViewById( R.id.butRington); // this is not working, set the size small so i can really tell mBut.setWidth(30); mBut.setOnClickListener(this);
layouut
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/butVol"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="24px"
android:text="Volume"
android:textColor="#ff0000ff"
/>
<Button
android:id="@+id/butRington"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="24px"
android:text="Rington"
android:textColor="#ff0000ff"
/>
Upvotes: 0
Views: 64
Reputation: 26
Getting the width of the screen:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x
Now you need to get your button, and then set the new width:
Button b = (Button) findViewById(R.id.button1);
b.setWidth(width);
Upvotes: 0
Reputation: 2237
After hanging layout_widht to wrap_content, I am able to change the width to what every size I need.
<Button
android:id="@+id/butRington"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R"
android:textColor="#ff0000ff"
android:textSize="24px" />
Upvotes: 0