0

I have a android view with 2 buttons centered. I want to change the button sizes to be bigger when I run the app on a tablet because they look ridiculous small there since it is the same size as for the phones.

How can I do this?

This is my code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#e9e9e9"
                android:orientation="vertical"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin" >

    <ImageView android:id="@+id/imageView1"
               android:layout_height="wrap_content"
               android:layout_width="wrap_content"
               android:layout_centerInParent="true"
               android_layout_gravity= "center"
               android:layout_marginLeft="30dp"
               android:layout_marginRight="30dp"
               android:src="@drawable/icon_bakgrund_android">
    </ImageView>

    <RelativeLayout

            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >

        <TableLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/TableLayout01"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_centerInParent="true"
                >


        <TableRow android:id="@+id/TableRow01"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content">

            <Button
                    android:id="@+id/button1"
                    android:layout_width="260dp"
                    android:layout_height="50dp"
                    android:background="@drawable/nybutton"
                    android:layout_below="@+id/button2"
                    android:text="@string/las_sollefteabladet"
                    android:textColor="#ffffff"
                    android:layout_centerHorizontal="true"/>


        </TableRow>

        <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:adjustViewBounds="true"
                  android:scaleType="centerCrop">
            <Button
                    android:id="@+id/button2"
                    android:layout_width="260dp"
                    android:layout_height="50dp"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/nybutton"
                    android:layout_centerInParent="true"
                    android:text="@string/annonsorer"
                    android:textColor="#ffffff"
                    />


        </TableRow>

        </TableLayout>

    </RelativeLayout>

    </RelativeLayout>
Cornelia G
  • 163
  • 1
  • 4
  • 12

6 Answers6

1

Here you go insert in the button code

android:layout_weight="some integer value according to your need"
Hassaan Rabbani
  • 2,469
  • 5
  • 30
  • 55
  • I havent used weight before so I dont know what weight to set? – Cornelia G Oct 25 '13 at 13:54
  • @CorneliaG giving weight for the button or to the layout means you are giving dynamic size setting for all the device available.Try this link http://stackoverflow.com/questions/2698817/linear-layout-and-weight-in-android – Akhilesh Sk Oct 26 '13 at 09:52
0

You can do either of the following

  1. make separate layout for large screen
  2. use layout:weight for the buttons. Hence the button size will be set depending on the screensize.
stinepike
  • 54,068
  • 14
  • 92
  • 112
0

Simply make a separate layout file and place it in the folder

'Layout-xlarge' or 'Layout-large'

Broak
  • 4,161
  • 4
  • 31
  • 54
0

You can create different dimen.xml for different screen densities, so you can have only one layout to adjust to multiple screens.

EDIT:

You have to create several folders for diferent densities (values-mdpi, values-hdpi, etc) and in each you create a dimens.xml . Then you add dimension items like this:

<dimen name="title_small_font_size">14sp</dimen>
<dimen name="header_title_font_size">32sp</dimen>

and so, in each file, adjusting the number as you need. And then, in your button you set the button attributes for example:

android:textSize="@dimen/grid_title_text_size"

Hope it helps.

Pablo_Cassinerio
  • 887
  • 5
  • 13
0

As far as my knowledge goes, giving static width and height for the button will not be good option here. All you have to do is to create a background image for the button for all type of mobile and tablet size and keep these images in appropriate drawable folders, and try to give the textAppearance for the text of the button like this:

android:textAppearance="?android:attr/textAppearanceLarge" 
Akhilesh Sk
  • 451
  • 4
  • 18
0

I copy and past my layout-folder, renamed it to layout-large (with a small l) and took in all my xml views and changed them and it works fine. Thanks!

Cornelia G
  • 163
  • 1
  • 4
  • 12