how to set the size and position of a button

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to set the size and position of a button

Postby drik_wen » Sat Jul 12, 2008 3:16 am

can somebody tell me how to set the size of the button that we make.
and also how to set its position.??
thx
drik_wen
Freshman
Freshman
 
Posts: 6
Joined: Sat Jul 12, 2008 3:00 am

Top

Postby zjsst1214 » Mon Jul 21, 2008 4:18 am

Hi,u can set the position use a layout like LinearLayout,RelativeLayout...
You can use android:layout_width and android:layout_height to set the size in your xml like this:

<Button android:id="@+id/play_button"
android:layout_width="60dip"
android:layout_height="60dip"
android:padding="10px"
android:text="PLAY"
android:layout_alignParentLeft="true"/>
纵马天涯
zjsst1214
Freshman
Freshman
 
Posts: 7
Joined: Fri Jun 13, 2008 7:42 am

Postby AsTeR » Mon Jul 21, 2008 2:59 pm

You can also set when you add your button through code by calling addView who take your component and a layout, the layout let you define size of components for example :
addView(myLabel, new AbsoluteLayout.LayoutParams(
10, LayoutParams.WRAP_CONTENT,0,0));

Here the first attribute are relative to the size.
AsTeR
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Jun 17, 2008 8:36 am

Postby Techno79 » Fri Dec 26, 2008 11:38 pm

zjsst1214 wrote:Hi,u can set the position use a layout like LinearLayout,RelativeLayout...
You can use android:layout_width and android:layout_height to set the size in your xml like this:

<Button android:id="@+id/play_button"
android:layout_width="60dip"
android:layout_height="60dip"
android:padding="10px"
android:text="PLAY"
android:layout_alignParentLeft="true"/>


I tried using this to centre the Button across the screen horizontally but it doesn't work. My XML snippet for the button is:

<Button
android:id="@+id/Button"
android:layout_height="wrap_content"
android:text="@string/buttonC"
android:layout_width="wrap_content"
android:layout_centerInParent="true" />

I've also tried using 'android:layout_centerHorizontal' and surrounding the Button XML in a <LinearLayout> tag as well.

Any help would be greatly appreciated. Thanks
Techno79
Freshman
Freshman
 
Posts: 6
Joined: Fri Dec 26, 2008 8:47 pm

Postby Techno79 » Sat Dec 27, 2008 12:00 am

Doh....I posted too quickly as I've now figured it out :)

Needed to put the button inside a RelativeLayout
Techno79
Freshman
Freshman
 
Posts: 6
Joined: Fri Dec 26, 2008 8:47 pm

Postby defdwight » Fri Jan 02, 2009 11:00 pm

You can also use the android:layout_x="XXpx" and android:layout_y="XXpx" tags within an AbsoluteLayout to specify exact placement.
defdwight
Freshman
Freshman
 
Posts: 6
Joined: Fri Jan 02, 2009 9:29 pm
Location: FL

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests