How to design a xml file to display in more screen - android

I'm new android programmer, I designed a page screen of 4". I've initialized with "dp" unit of measurement.
but when I run my project in screen of 10" or 7" or 3"2 components go wrong.
I learned dp is for all of screen, but I don't know why my page not be set to all of screens.

If you could include any code of your XML file, that would be very helpful.
Aside from that, I believe you haven't set android:layout_width and android:layout_height so you are getting odd looking sizes for the other display sizes of you XML.
Add
android:layout_width="match_parent"
android:layout_height="match_parent"
to your <RelativeLayout>
e.g.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
...
>
If you do in fact have this or it does not help with your issue
, then please respond with an example of your code.

my xml file is here, but I set visibility of one linearlayout to gone
and when user touch button the linearlayout will be visible and another linearlayout will be gone
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainLayout"
android:background="#drawable/darirann"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layoutTerm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<ScrollView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_marginTop="200dp"
android:layout_height="150dp">
<LinearLayout
android:padding="5dp"
android:layout_width="wrap_content"
android:background="#ffffff"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/firstpageabout" />
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/btnLoad"
android:layout_gravity="center"
android:textColor="#ffffff"
android:background="#114E7D"
android:gravity="center"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:text="ادامه"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutData"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone">
<Spinner
android:id="#+id/spState"
android:paddingRight="5dp"
android:layout_gravity="center"
android:background="#D3D3D3"
android:textSize="12sp"
android:layout_marginTop="200dp"
android:layout_width="150dp"
android:gravity="center"
android:layout_height="40dp" />
<Spinner
android:id="#+id/spCity"
android:paddingRight="5dp"
android:layout_gravity="center"
android:background="#D3D3D3"
android:textSize="12sp"
android:gravity="center"
android:layout_marginTop="5dp"
android:layout_width="150dp"
android:layout_height="40dp" />
<Button
android:layout_gravity="center"
android:id="#+id/btnNext"
android:textColor="#ffffff"
android:background="#114E7D"
android:layout_marginTop="10dp"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="مرحله ی بعد" />
<Button
android:layout_gravity="center"
android:id="#+id/btnUpdate"
android:visibility="invisible"
android:textColor="#ffffff"
android:background="#840101"
android:layout_marginTop="80dp"
android:layout_width="200dp"
android:layout_height="40dp"
android:text="دریافت نسخه ی جدید این برنامه" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgAds"
style="?android:attr/buttonStyleSmall"
android:layout_width="150dp"
android:layout_height="75dp"
android:visibility="gone"
android:layout_gravity="center_horizontal|center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

Related

How to align the layouts properly in Android?

I want to align a scrollable TextView above a RelativeLayout) with 3 buttons at the bottom and a SeekBar above this buttons. The problem with my code is that the RelativeLayout takes the entire screen.
Here's my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/images"
android:orientation="vertical"
tools:context="com.example.acer.aartisangrah.ekdanta">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textView9"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:enabled="true"
android:focusable="true"
android:longClickable="true"
android:textIsSelectable="true" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/b9"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:onClick="decrease"
android:background="#drawable/zoomout1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/b10"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="increase"
android:layout_marginRight="10dp"
android:background="#drawable/zoomin1"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/button19"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/play"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBar"
android:layout_above="#+id/b9"
android:configChanges="orientation|screenSize"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/b10"
android:layout_alignRight="#+id/b10"
android:layout_alignEnd="#+id/b10"
android:layout_weight="1"/>
</RelativeLayout>
</LinearLayout>
Check this image
Change the height of the ScrollView to android:layout_height="wrap_content"
and remove the android:layout_weight="1"
The following layout should do the job. Firstly, there was a circular dependency in height among <RelativeLayout> and <SeekBar>, so I fixed the height of <SeekBar>. Secondly, the android:layout_alightParentBottom="true" was messing with the layout manager, so removed that. Finally, moved the <SeekBar> above the buttons to easily manage the layout description. Here's the updated code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/images"
android:orientation="vertical"
tools:context="com.example.acer.aartisangrah.ekdanta">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textView9"
android:enabled="true"
android:focusable="true"
android:longClickable="true"
android:textIsSelectable="true" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<SeekBar
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/seekBar"
android:configChanges="orientation|screenSize"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/b10"
android:layout_alignRight="#+id/b10"
android:layout_alignEnd="#+id/b10"/>
<Button
android:id="#+id/b9"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:onClick="decrease"
android:layout_below="#id/seekBar"
android:background="#drawable/zoomout1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/b10"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:onClick="increase"
android:layout_below="#id/seekBar"
android:layout_marginRight="10dp"
android:background="#drawable/zoomin1"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/button19"
android:layout_below="#id/seekBar"
android:layout_centerHorizontal="true"
android:background="#drawable/play"/>
</RelativeLayout>
</LinearLayout>
Your problem is you set ScrollView android:layout_height="0dp" and android:layout_weight="1"
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
and
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
so ScrollView takes nothing for hight
Edit
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
You can set android:layout_weight="1" as you want ratio between ScollView and RelativeLayout. Hare both will get half(1/2) of screen.

Android Diamond Button Layout

I am currently working on a sample application using android studio. I need to design diamond shaped buttons and view them as follows (Screenshots attached). But I don't have an idea how to make this kind of thing with android.
There are be four diamond shaped buttons, and they are be aligned as according to the following screenshot.
Screenshot:
Here is sample code adjust margins according to devices you can use imageView instead buttons
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/firstRow"
android:rotation="-30"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Button 2"
android:id="#+id/button2" />
<Button
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Button 1"
android:id="#+id/button1"/>
</LinearLayout>
<LinearLayout
android:id="#+id/secondRow"
android:layout_below="#+id/firstRow"
android:rotation="-30"
android:layout_marginTop="24dp"
android:layout_marginLeft="68dp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Button 4"
android:id="#+id/button4" />
<Button
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Button 3"
android:id="#+id/button3"/>
</LinearLayout>
</RelativeLayout>
The easiest way is use .png archives on ImageButtons and display them on a RelativeLayout. You can change positions and adjust them as you wish. If you set the android:background="#android:color/transparent" you can set your form, by playing with the margins (android:layout_marginRight="", android:layout_marginTop="", etc.)
With that I got this:
This is the code I used; it's only necessary .xml, without programmatic changes:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_purple"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="39dp"
android:background="#android:color/transparent"
android:contentDescription="#string/im"
android:src="#drawable/diamond" />
<ImageButton
android:id="#+id/ImageButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton1"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:contentDescription="#string/im"
android:src="#drawable/diamond" />
<ImageButton
android:id="#+id/ImageButton04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/ImageButton03"
android:layout_below="#+id/imageButton1"
android:layout_marginRight="55dp"
android:layout_marginTop="47dp"
android:background="#android:color/transparent"
android:contentDescription="#string/im"
android:src="#drawable/diamond" />
<ImageButton
android:id="#+id/ImageButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/ImageButton03"
android:layout_alignRight="#+id/ImageButton04"
android:layout_marginBottom="66dp"
android:layout_marginRight="5dp"
android:background="#android:color/transparent"
android:contentDescription="#string/im"
android:src="#drawable/diamond" /></RelativeLayout>
Hope it helps.
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/splash2"
tools:context="com.example.sv.myfoodapplication.view.SplashActivity">
<LinearLayout
android:id="#+id/sp_breakfast"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_above="#+id/sp_desert"
android:layout_alignStart="#+id/sp_vegetable"
android:layout_marginBottom="43dp"
android:orientation="vertical"
android:gravity="center"
android:background="#drawable/shape_diamond">
</LinearLayout>
<LinearLayout
android:id="#+id/sp_meat"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignBottom="#+id/sp_vegetable"
android:layout_alignStart="#+id/sp_desert"
android:layout_marginBottom="80dp"
android:orientation="vertical"
android:gravity="center"
android:background="#drawable/shape_diamond" >
</LinearLayout>
<LinearLayout
android:id="#+id/sp_vegetable"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignBottom="#+id/sp_desert"
android:layout_alignParentStart="true"
android:layout_marginBottom="83dp"
android:layout_marginStart="19dp"
android:orientation="vertical"
android:gravity="center"
android:background="#drawable/shape_diamond" >
</LinearLayout>
<LinearLayout
android:id="#+id/sp_desert"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:gravity="center"
android:background="#drawable/shape_diamond">
</LinearLayout>
</RelativeLayout>

android layout center and bottom

In my layout i want to display two imagebuttons in the center and a my amountmeter below it on the bottom, all centered vertically, i have tried many ways but cant seem to find that perfect layout. all the component align vertically and center but it makes my amountmeter small and not full width of the screen.
How it should be
how it is now
updated code
current layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_sell" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center|bottom"
android:padding="4dp" />
COPY PASTE BELOW 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:orientation="horizontal" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/purchase"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/sell"
android:padding="4dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
AFTER THAT
android:background="#drawable/round_button"
android:src="#drawable/ic_sell"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart"
PUT THIS LINE TO YOUR TWO IMAGE BUTTONS SURELY IT WILL WORK FOR YOU
One Linear layout is enough for this. Do not put your AmountMeterView into it's own LinearLayout.
Just make one Linear layout (vertical), and put all three elements in there. Gravity center_horizontal for all elements.
Try in this way hope this will help you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" >
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp" />
</LinearLayout>
</LinearLayout>

popup window layout design left blank space

My popup window design left blank space on top of the window. i try different layout options but space persist.i don't understand how to eliminate this.i am using Custom popup Please help.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#FFF"
android:text="Input a Value"/>
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/severity_rating"
android:layout_marginRight="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/popup_et"
android:layout_height="wrap_content"
android:layout_width="100dp"
android:inputType="number" />
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Ok"/>
<Button
android:id="#+id/dialogButtonCancel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="cancel"/>
</LinearLayout>
</LinearLayout>
use dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Setting height to fill_parent to the first linear layout doesn't help ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
Try this..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
and your imageview give as src
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/severity_rating"
android:layout_marginRight="5dp" />
Use android:layout_weight="" for your linearlayout objects and arrange their appearance in window. Use especially for the item which will occupy more space.
Popup Window
for this view, I use
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/popborder_record"
android:orientation="vertical">
<TextView
android:id="#+id/tvCHLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_blue_grey_200"
android:text="#string/checklistsetup"
android:textAlignment="center"
android:textSize="#dimen/text_size"
android:textStyle="bold" />
<ListView
android:id="#+id/lvCheckList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="8" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="#string/lblSoru"
android:textSize="25sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/lblPuan"
android:textSize="25sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_weight="9"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="10"
android:inputType="number"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnAdd"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnCHSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/strSave" />
<Button
android:id="#+id/btnCLClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/strOFF" />
</LinearLayout>
If you use weight on each element with will also cause spaces. So use for object for important.

Android Relativelayout two buttons rightof one button

I was wondering how to use Relativelayout in order to make a tructure like this:
three buttons, let's call them A B and C; I want to put B and C one above the other and both of them on the right side of A as a single block matching the same width and height of A (so we'll have that B and C have half height of A but the same width).
Since I can't post images yet here you can find the image of what I'm looking for: http://img191.imageshack.us/img191/9765/stackg.jpg
The code I wrote about this part is this one:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<Spinner
android:id="#+id/A"
android:layout_width="0dp"
android:layout_height="96dp"
android:layout_below="#id/another_block_that_fills_all_the_line"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/B" />
<Spinner
android:id="#id/B"
android:layout_width="96dp"
android:layout_height="48dp"
android:layout_below="#id/another_block_that_fills_all_the_line"
android:layout_alignParentRight="true" />
<Spinner
android:id="#id/C"
android:layout_width="96dp"
android:layout_height="48dp"
android:layout_below="#id/B"
android:layout_alignParentRight="true" />
</RelativeLayout>
The problem is that it's not going to scale with every screen because I had to set static sizes. I tried a lot of different solutions like using all the possible combinations for the layout_align and changing wrap_content even randomly but still, I can't fit them in the way I want them to without using static sizes.
Use LinearLayout with layout_weight. Try this layout
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:layout_width="0dip" android:layout_height="fill_parent"
android:layout_weight="1.0"/>
<LinearLayout android:layout_width="0dip" android:layout_height="fill_parent"
android:layout_weight="1.0" android:orientation="vertical">
<Button android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1.0"/>
<Button android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1.0"/>
</LinearLayout>
</LinearLayout>
Try this,
<?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="#android:color/black">
<Button
android:id="#+id/A"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/relativeLayout"
android:layout_alignBottom="#+id/relativeLayout"
android:text="AAA"/>
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/A"
android:layout_centerVertical="true"
android:background="#android:color/black">
<Button
android:id="#+id/B"
android:layout_width="wrap_content"
android:text="BBB"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/B"
android:text="CCC"/>
</RelativeLayout>
</RelativeLayout>
It should be as below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:padding="10dp" >
<View
android:id="#+id/helper"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Spinner
android:id="#+id/A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/helper"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/A"
android:layout_alignParentRight="true"
android:layout_alignTop="#id/A"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/helper"
android:orientation="vertical" >
<Spinner
android:id="#+id/B"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:background="#android:color/black" />
<Spinner
android:id="#+id/C"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/black" />
</LinearLayout>

Categories

Resources