I preview my Android app in a Nexus 4 :). Here it is
But when I try to preview it on a Nexus 7 emulator, :(
I think that I'm having issues on supporting multiple screens on my game.
My question is, how can I make it look bigger on nexus 7 or 10 or any other devices?
By the way, I placed my images (board.png,small_hole.png, big_hole.png and bg.png) on drawable-xhdpi folder (I'm using Android Studio)
Do you think I used the wrong layout or properties in my xml file? Is there something wrong in my code?
This is my xml layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg.png>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/board"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/big_hole" >
</ImageView>
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="2dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/small_hole" >
</ImageView>
// paste 6 more ImageViews here
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="7dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/small_hole" >
</ImageView>
// paste 6 more ImageViews here
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:background="#drawable/big_hole" >
</ImageView>
</FrameLayout>
</LinearLayout>
</RelativeLayout>
thank you guys..
Nexus 4 access drawable-xhdpi resources and
Nexus 7 access drawable-large-tvdpi or drawable-sw600dp-tvdpi resources.
Nexus 10 access drawable-xlarge-xhdpi or drawable-sw720dp-xhdpi resources.
and u should resize ur image and u shud put in respective folders.
and Nexus 4 is 4.7 inch (768*1280) of size and Nexus 7 is 7 inch (800*1280) of size.
more info:
Different resolution support android
Application Skeleton to support multiple screen
Is there a list of screen resolutions for all Android based phones and tablets?
Try placing youre images in res/mdpi they will be streched to fit screens which are bigger (hdpi, xhdpi)
(if i remember correctly the modyfiers are x1.5 and x2 for hdpi and xhdpi).
Alternatevly you can make a layout folder for larger screens ie. layout-sw720dp and create a new layout file there.
Related
RecyclerView item layout, padding and margins are conflicts on typical phone screen 480x800 hdpi. Other than 480*800 hdpi, layout design showing perfect for normal screens.
Samsung J1 Ace DisplayMetrics values :
DisplayMetrics{density=1.5, width=480, height=800, scaledDensity=1.1850001, xdpi=217.714, ydpi=216.17}
I have created layout folder for layout-w320dp and replaced below xml, which was working fine on normal layouts (Normal mobile screens).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardViewDashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/paddingDefault"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="#dimen/paddingDefault"
card_view:cardCornerRadius="0dp"
card_view:cardMaxElevation="#dimen/paddingDefault"
card_view:contentPadding="#dimen/paddingDefault">
<LinearLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<LinearLayout
android:id="#+id/circle_layout"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="#drawable/ic_legend"
android:gravity="center">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgViewDashboard"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center|center_horizontal"
android:tint="#color/toolBar"
card_view:srcCompat="#drawable/ic_dashboard" />
</LinearLayout>
<TextView
android:id="#+id/txtViewDashboard"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/imgViewDashboard"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/title_dashboard"
android:textAppearance="#style/TextAppearance"
android:textColor="#color/toolBar" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Layout which having padding and margin problems for 480*800 hdpi screenshots FYR, also i have tried SO answers but i didn't get any ideas.
Anybody knows, how to resolve this issue? Please share your ideas.
You can generate a new layout folder inside res for support.
Regarding dimensions, please check below link. That will help you.
https://developer.android.com/guide/practices/screens_support.html
You can create a new layout-large folder in res. Add your XML in this folder. That way you can manage it.
e.g.
res/layout-large/activity_main.xml
You can create new layout as per your requirement from Android studio.
Right click on layout=>New=> layout resource file
Customize as per your requirement and generate.
I have a listview layout with images
It looks like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="240dp"
android:adjustViewBounds="true"
android:id="#+id/listview_item_imageView"
android:layout_gravity="center_horizontal|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FAC308"
android:id="#+id/listview_item_title"
android:text="TITLE"
android:textSize="20sp"
android:paddingBottom="40dp"
android:layout_centerInParent="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:id="#+id/listview_item_subtitle"
android:paddingTop="40dp"
android:text="SUBTITLE"
android:textSize="20sp"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/orangeSeparator"
android:src="#drawable/orangeseparator"
android:layout_centerInParent="true" />
If I run it on device with 720x1280 240dpi it looks like this
If I run it on device with 720x1280 320dpi it looks like this
I get images from the internet, so I cant prepare different versions.
How to make it look similar across all the devices ?
You can use fitXY Android Developer,
android:scaleType="fitXY"
or you can also create different drawable resources from the original one, with Photoshop or any similar program
in your container you have
android:layout_height="match_parent"
and in the image:
android:layout_height="240dp"
you have to have the same height or 'wrap_content' for your container not to have those gaps.
you can also add to the imageview:
android:scaleType="centerCrop"
another thing is that you can use specific library to handle loading of network images.
You can look this article . Make your app supporting different dpi variations and different screen types: Supporting Different Screens
I'm trying to create an app that is suitable for any kind of screen.
I created 4 different layout types ( layout - sw320dp , 480dp , 600dp , 720dp )
I am currently proceeding for "step " and I started to create the layout for devices that fall within sw-720dp then average for devices from 10 "
This is the activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<include layout="#layout/toolbar" />
<FrameLayout
android:layout_below="#+id/toolbar"
android:id="#+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:foreground="#drawable/shadow_toolbar"/>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/nav_body_main" />
</android.support.v4.widget.DrawerLayout>
Then I designed the layout for a fragment ... and I added a button and the floating action button to insert ourselves as social references ( facebook twitter etc ) .
With the latter I gave the size in dp and increasingly distances dp in the one of the more
This is code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingEnd="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Button
android:id="#+id/button_vai_assistenza"
android:layout_width="540dp"
android:layout_height="65dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_button"
android:text="INIZIA SUBITO!"
android:textColor="#drawable/custom_textcolor_button"
android:textSize="20dp" />
<TextView
android:id="#+id/textView_nome_app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView_logo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="20dp"
android:text="Assistenza Copyworld"
android:textColor="#000000"
android:textSize="35dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView_logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="30dp"
android:src="#drawable/logo_nav_grande" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView_copyright_benv"
android:layout_alignStart="#+id/textView_copyright_benv"
android:layout_below="#+id/button_vai_assistenza"
android:layout_marginTop="122dp"
android:text="www.copyworld.it"
android:textSize="25dp" />
<RelativeLayout
android:id="#+id/RelativeLayout_social"
android:layout_width="wrap_content"
android:layout_height="95dp"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="12dp"
android:orientation="horizontal">
<android.support.design.widget.FloatingActionButton
android:id="#+id/float_social_facebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="false"
android:src="#drawable/fb_icon_social"
app:backgroundTint="#drawable/custom_floating_action_button" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/float_social_twitter"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_toEndOf="#+id/float_social_facebook"
android:layout_toRightOf="#+id/float_social_facebook"
android:src="#drawable/tw_icon_social"
app:backgroundTint="#drawable/custom_floating_action_button" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/float_social_linkedin"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_toEndOf="#+id/float_social_twitter"
android:layout_toRightOf="#+id/float_social_twitter"
android:src="#drawable/li_icon_social"
app:backgroundTint="#drawable/custom_floating_action_button" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/float_social_youtube"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_toEndOf="#+id/float_social_linkedin"
android:layout_toRightOf="#+id/float_social_linkedin"
android:src="#drawable/yt_icon_social"
app:backgroundTint="#drawable/custom_floating_action_button" />
</RelativeLayout>
<TextView
android:id="#+id/textView_copyright_benv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="22dp"
android:text="Copyright © 2016 Copyworld srl " />
</RelativeLayout>
I then launched the app on the 3 tablet I have available .. (namely a galaxy tab 2 10.1, a galaxy tab A and galaxy tab E).
As soon as the app is open on the 3 devices I noticed this thing "abnormal" ...
The "social icons" and the TextView were at different distances between them ... (
in particular of the galaxy tab 2 10.1 and Galaxy Tab E,) while the Galaxy tab A icons and TextView are at the right distance as set in 'xml ...
How come the two devices distances not only equal to the right device ?? (The two devices have the text and view the icons at equal distances but different from the one on the Galaxy Tab A)
As for other components such as (image view with the app icon and the TextView with the name of the app) the dimensions and distances have been respected ...
How can I do to make everything in a "perfect adaptable layout" on all devices without each they assume proportions and distances different ??
I read the official guide to this topic, where he speaks of dp, its layout etc.
I leave the pictures attached of 3 devices.
You can use google library PercentRelativeLayout with this library you can set width and height of your views by percentage which is great because in all screen they look the same and of course it is not hard to code it. Here example:
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentRelativeLayout>
also add this line in your build.gradle
dependencies {
compile 'com.android.support:percent:23.2.0'
}
and official documentation by Google https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html
If you have some questions, feel free to ask.
Create three different Layouts Folder in your res folder for all devices and use the dimensions accordingly.
Generic Layout Folders
res/layout-small
res/layout-normal
res/layout-large
res/layout-xlarge
After you are done with making your Normal/Medium Layouts follow these steps:
Convert the Normal Dimensions for other Screen Sizes.
Copy your Normal Layout xml files in to other Folders.
Change the suffix of the dimensions used according to the folder that you are in
Resize the Image Resources in your drawable folder (Width and Height - Same technique as we used for converting the dimens) and put them in their respective drawable folder (drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xdpi and so on).
Then your Layouts should work on every device with correct positioning.
For converting Values
0.75 - ldpi (small) //mdpi dimens *0.75
1.0 - mdpi (normal) //First create these dimensions
1.5 - hdpi (large) //mdpi dimens *1.5
2.0 - xhdpi (xLarge) //mdpi dimens *2.0
For Example
android:layout_width="66dip" //in normal
android:layout_width="100dip"//in large 66*1.5=100(approx)
android:layout_width="52dip" //in small 66*0.75=52(approx)
Also new Qualifier has been introduced
- SmallestWidth
- AvailableScreenWidth
- AvailableScreenHeight
read more about it here https://developer.android.com/guide/practices/screens_support.html
I hope this helps.
I am making an android application in which I am using an ImageView.My image is displaying perfectly on Normal phone screen,
but on big screen devices like Tabs, it is getting smaller and on the left side of the screen.So what is the most appropriate solution for the same?
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#550e8c" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#550e8c"
android:text=""
android:textColor="#e2ffff" />
<Button
android:id="#+id/help"
android:layout_width="52dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView2"
android:background="#550e8c"
android:drawableLeft="#drawable/help1" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl"
android:background="#E5E3E4"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home"
android:adjustViewBounds="true"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#781a8f"
android:drawableLeft="#drawable/earthnew1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/aware_patient"
android:textColor="#e2ffff"
android:textStyle="bold" />
<Button
android:id="#+id/btnCardiology_updates"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
android:background="#781a8f"
android:drawableLeft="#drawable/updates1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/Cardiology_updates"
android:textColor="#e2ffff"
android:textStyle="bold" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
android:background="#781a8f"
android:drawableLeft="#drawable/linknew1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/useful_links"
android:textColor="#e2ffff"
android:textStyle="bold" />
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
android:background="#781a8f"
android:drawableLeft="#drawable/linknew1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/Useful_journlas"
android:textColor="#e2ffff"
android:textStyle="bold" >
</Button>
</LinearLayout>
</RelativeLayout>
You have used an image named home in same resolution for different drawable folder.
For supporting tablets also, use large, xlarge qualifiers. Nexus 7 is a large-hdpi tablet(technically it's tvdpi, but takes images from hdpi). So if you want to put images for Nexus 7, make a folder named drawable-large-hdpi and put the images there.
Now regarding the 10 inch tablets case, they are xlarge devices and their densities can change from mdpi to xhdpi(Nexus 10). But many have resolution of 1280 * 800 and they are mdpi devices.
Create drawable folder like this
// for Phones
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
//for 7 inch tablets
drawable-large-ldpi
drawable-large-mdpi
drawable-large-hdpi(for Nexus 7)
// for 10 inch tablets
drawable-xlarge-mdpi
drawable-xlarge-xhdpi(for nexus 10)
Create home.png for different resolution. Here is the list of resolution for whole screen slice your image according to your requirement
320 X 480 for mdpi
480 X 800 for hdpi, large-ldpi
600 X 1024 for large-mdpi (7 inch tablet)
720 X 1280 for xhdpi (s3, nexus 4)
800 X 1280 for large-hdpi, xlarge-mdpi (nexus 7, other 10 inch
tablet)
1080 X 1920 for xxhdpi (s4, s5, nexus 5)
2560 X 1600 for xlarge-xhdpi (nexus 10)
You are using the Image view inside the Linear Layout, evethough the imageview width is wrap_content the layout width is fill_parent. Change this as wrap_content...
Like This
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rl"
android:background="#E5E3E4"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home"
android:adjustViewBounds="true"/>
</LinearLayout>
issue is that you are putting same image in each folder. As Tablet and phone has different resolution you need different resolution image for them. If you using same image then you will face issue in one of the device.
You need to use Linear layout and Image view with fill_parent or weight option , and use margin from left , right , bottom and top . so your image view and linear layout will expand according to your screen resolution .
Okay!
I am developing android application right now, but I want to know how I can fit all the layoutouts to the a multiple device screens.
* I did made multiple screen folders.
res/layout-small/main.xml
res/layout-normal/main.xml
res/layout-large/main.xml
res/layout-xlarge/main.xml
* Here is an example of my code.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="120dp"
android:layout_height="70dp"
android:text="#sting/button1" >
<Button
android:layout_width="120dp"
android:layout_height="70dp"
android:text="#sting/button2" >
<Button
android:layout_width="120dp"
android:layout_height="70dp"
android:text="#sting/button3" >
<Button
android:layout_width="120dp"
android:layout_height="70dp"
android:text="#sting/button3" >
</LinearLayout>
</LinearLayout>
As you can see, I used 120dp for every buttons.
When I ran in the virtual device machine, the screen is fit. (Because I used 480dp width screen in virtual device machine.)
However, when I ran in real cell phone devices (Mine: SamSung Galaxy Note 1(Korean version), my dad's: SamSung Galaxy S2(Korean version), and my mom's: SamSung Galaxy S(Canadian version)), even though I created different screen size of folders, I can see the (width) of the button is go too far from the device's screen layout.
Can anyone tell me how I can fit to all the device screen?
Can I still use dp in this case? (Please give me an example too!)
You need to read up on using LinearLayout and RelativeLayout (and other layouts). You're not using their layout parameters at all. You shouldn't need to specify any specific size (like 120dp) to support multiple screen sizes for your situation.
http://developer.android.com/guide/topics/ui/declaring-layout.html
Here's what you should do:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#sting/button1"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#sting/button2"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#sting/button3"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#sting/button4"
android:layout_weight="1" />
</LinearLayout>