I have this simple 'XML' layout. I have tested in various devices and emulators and works fine. But on Galaxy Tab Samsung 9.6inch (1280x800) 157 dpi, text customer gets cropped in the end & becomes "custom".
I have read that i should declare dimens xml for various densities but i thought using DP is what makes your layout look the same in all devices. Am i wrong?
Also this tablet is a ldpi and x-large screen. I have tested it in other similar devices with similar specs and works well. How should i make this work for this device?
NOTE I want specifically 100dp to match others texts in width
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/labelSelGateName"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_paddingLeft="16dp"
android:text="customer" />
</LinearLayout>
There could be the issue of TextSize in that device. Have you tried playing with the text size?
Is this layout is in any other layout?
Its happening because u have used padding on whole side.just set padding only top and bottom as u have only fixed the width.then it should be worked
to support padding just follow below-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/labelSelGateName"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_paddingLeft="16dp"
android:layout_paddingRight="16dp"
android:text="customer" />
</LinearLayout>
Related
I've already created the layout-sw720dp but I don't know if I have to change all of the sizes of those Layouts,I mean I have layout-sw330dp, layout-sw480dp, and so on, I have to change the size of TextView, Button, and all of the stuff on the layout?
Is there any option to make it dynamic instead of changing it manually?
Edit
My problem is when I run my app on a Nexus5 for instance it looks good, all size is correct, but when I try to run my app on Nexus9 all of the widgets are smalls (buttons, textviews, etc...)
The recent update to TextViews in support library v26 was built for just this purpose:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform"
app:autoSizeMinTextSize="12sp"
app:autoSizeMaxTextSize="100sp"
app:autoSizeStepGranularity="2sp" />
</LinearLayout>
I wrote a test application to describe my problem better. I started a new Android project with this activity:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.jannevers.myapplication.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Now the first problem is, the button does not really fill the parent, it has a margin (see screenshot):
I can work around this, by making the button bigger than it should be.
But then the second problem is, that the margin is the same on the most devices, but not all. E.G. at a Samsung Galaxy S6 Edge, there is almost no margin (see screenshot):
This is really weird, anyone know a solution?
Use style="?android:attr/borderlessButtonStyle"
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?android:attr/borderlessButtonStyle"/>
Check if into your style.xml there is a rule about layout margin like this:
<item name="android:layout_margin">10dp</item>
I'm very disappointed. I just finished my project based on 360dp for "normal screens", but when I tried to run in Motorola Atrix I had a surprise. Motorola Atrix is 360dp instead 320dp, because his width is 540px. Now I'm breaking my head to find out that problem to be resolved. How can I create a layout for 360dp?
I tried all of these:
res/values-sw360dp
res/layout-sw360dp
main.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"
android:background="#DFEFF1">
<Button
android:background="#AAAA11"
android:id="#+id/button1"
android:layout_width="#dimen/default_width"
android:layout_height="#dimen/default_height"
android:text="SOME TEXT 1"
/>
<Button
android:background="#FFAA11"
android:id="#+id/button2"
android:layout_width="#dimen/default_width"
android:layout_height="#dimen/default_height"
android:text="SOME TEXT 2"
android:layout_alignParentRight="true" />
</RelativeLayout>
res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="default_width">160dp</dimen>
<dimen name="default_height">160dp</dimen>
</resources>
Motorola Atrix
Samsung Galaxy SII
Generally when designing your layout you want to avoid planning for a specific pixel size. If you were to separate all of your layouts based on pixels like you want to, then you'd have to almost provide one layout for every single device (There are so many devices with different sized screens in the world). Usually you'll want to provide layout resources for a few different categories of size. layout-small, layout-normal, layout-large, etc. If you provide those and your layouts are built in a good manner it should scale to the different sized devices pretty well.
Is there something specific that is wrong with your layout when you run it in the larger sized device? Perhaps if you post that I can help you to try to solve it without needing to separate your layouts by pixel size.
Supporting Multiple Screens in the developer docs has lots of great information about how to build your applications so that they will scale well.
EDIT:
One potential way to solve your problem is not use a static dp value for the width, instead allow the buttons to grow to takeup however much space (horizontally) in order to fill up the width of the screen. You can do that with layout_weight and setting the width to fill_parent. I don't have access to eclipse now so I can't test, but I think surely there is also a way you could get this effect without the linearlayout, but this was the first way that I thought of.
<?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:background="#DFEFF1">
<LinearLayout
android:id="#+id/buttonRow"
android:orientation="horizontal"
android:layout_height="#dimen/default_height"
android:layout_width="fill_parent">
<Button
android:background="#AAAA11"
android:id="#+id/button1"
android:layout_width="0"
android:layout_height="#dimen/default_height"
android:text="SOME TEXT 1"
android:layout_weight="1"
/>
<Button
android:background="#FFAA11"
android:id="#+id/button2"
android:layout_width="0"
android:layout_height="#dimen/default_height"
android:text="SOME TEXT 2"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
I have created layout,layout-large, layout-small layout-xlarge layout_xlarge-land but if i have created emulator with giving resolution my design is coming good . but i have checked in devices samsung galaxy tab 7 inch and samsung nexus s but my design in not properly coming can anybody tell what is problem? otherwise how to do?
This is my layout for large screen
<?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:background="#FFFFFF"
android:layout_marginLeft="10dip"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:text="Large Screen" />
<fragment class="com.hcl.gcm.fragment.MeetingFragment"
android:id="#+id/meetingFrag"
android:layout_marginTop="200dip"
android:layout_width="match_parent"
android:layout_height="200dip"/>
<fragment class="com.hcl.gcm.fragment.MeetingRecieveFragment"
android:id="#+id/receivingFrag"
android:layout_marginTop="100dip"
android:layout_width="match_parent"
android:layout_height="200dip"/>
<fragment class="com.hcl.gcm.fragment.ButtonFragment"
android:id="#+id/btnFragment"
android:layout_marginTop="40dip"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Thanks
The design for Multiple Screen size is always a difficult one in Android.
Some Guidelines I know:
Mostly Use Relative Layouts which suit any screen size.
If you design for different screen sizes, then using different size images are good.
Try to use Nine Patch PNGs for Button backgrounds.
Design a separate App if you develop App also for Tablets. Because Tablet users want rich graphic UIs.
Always check UI in multiple size emulators during development.
I got a problem in a project with the following structure. On each emulator (also large screens) a button positioned within a simple relative layout using that code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/first_bg" >
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="202dp"
android:layout_marginRight="54dp"
android:background="#drawable/m_button"
android:text="#string/next" />
</RelativeLayout>
appears fine. BUT testing the app on Galaxy Note has shown that the button just flies away to some crazy positions. I used an emulator with similar configuration and the button appeared properly. I have no idea where the problem could be..
Have you tried to use a linearlayout instead?
With it you don't nedd to set the margin, just the position
It's based on the density-independent pixels (dp units), it'll show up at different positions on different phones.
http://developer.android.com/guide/practices/screens_support.html#density-independence