Omid Zamani
Omid Zamani

Reputation: 424

setting fit size for button and textview and text

I'm new developer for android. I build new program for android, but when I install it in different device (different screen size) , do not change automatically the size of buttons in my program, for example: i built the program on 4 inches device(emulator), i install it in Samsung galaxy S , every things are in their place, but when i install the program in Samsung galaxy S III, the buttons are smaller then the screen size. now, how can i fit the size of buttons by devices screen size????

Upvotes: 0

Views: 1221

Answers (2)

Amit Gupta
Amit Gupta

Reputation: 8939

You should use Dimension. For reference go through Dimension

FILE LOCATION:
res/values/filename.xml
The filename is arbitrary. The <dimen> element's name will be used as the resource ID.


res/values/dimens.xml

res/values-small/dimens.xml

res/values-normal/dimens.xml

res/values-xlarge/dimens.xml

and define the size here

<dimen name="font_size">18sp</dimen>

and use it like

<TextView
    android:layout_height="@dimen/textview_height"
    android:layout_width="@dimen/textview_width"
    android:textSize="@dimen/font_size"/>

But you need to define dimension for each screen size.

Upvotes: 0

Kent Andersen
Kent Andersen

Reputation: 2201

Some code would help a lot in this situation. However, Please insure you are using DIP instead of pixels. And if you really need to, you can use a Linear Layout and add weights.

        <Button
                android:id="@+id/button_name"
                android:layout_width="50dip"
                android:layout_height="wrap_content"/>

Upvotes: 1

Related Questions