android


Layout looks different on devices


Hi My app looks different on different devices. I use Samsung Galagy S2 as my testing device, but when I tried install app to another device Samsung Galaxy Note 3.
Display resolution:
Samsung galaxy S2: 800x480(hdp)
Samsung galaxz Note 3: 1920x1080(xxhdp)
My app looks on:
Samsung galaxy S2 like THIS
Samsung galaxy Note 3 like THIS
As you can see in first picture it looks good but on Note 3 there are a lot of empty space at bottom of app. All images I use are xxhdp and hdp too. The problem is in gap between buttons. I set it in dp so I thought in every device it will look like in my phone. But on galaxy S2 and galaxy Note 3 it looks same gap.
This is my layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayoutHA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/background" >
<RelativeLayout
android:id="#+id/relativeLayoutHA"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/info"
/>
<Button
android:id="#+id/facebookButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/infoButton"
android:layout_marginRight="5dp"
android:background="#drawable/facebook"
/>
<Button
android:id="#+id/emailButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/facebookButton"
android:layout_marginRight="5dp"
android:background="#drawable/email"
/>
</RelativeLayout>
<Button
android:id="#+id/animal"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="#drawable/shape_button"
android:drawableLeft="#drawable/animal_pic"
android:text="Animals" />
<Button
android:id="#+id/insect"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/shape_button"
android:drawableLeft="#drawable/insect"
android:text="Insects" />
<Button
android:id="#+id/nature"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/shape_button"
android:drawableLeft="#drawable/nature"
android:text="Nature" />
<Button
android:id="#+id/people"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/shape_button"
android:drawableLeft="#drawable/people"
android:text="People" />
<Button
android:id="#+id/gun"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/shape_button"
android:drawableLeft="#drawable/gun"
android:text="Guns" />
</LinearLayout>
You should use the LinearLayout to cover all your vertical buttons and set the layout_height of this LinearLayout to match_parent.Inside this LinearLayout, set the layout_weight for each button to same value(ex:1) and layout_height to 0dp
You have to manage height and width with dimen.create a dimen for values-v11,values-v14,values-sw600dp values layout and set height and width based on layout and check.
I also had same issue, but i solved it by creating 3 different layouts for same activity.
layout_large(for xhdp layouts)
layout_xlarge(for xxhdp layouts)
layout(for xhdp layouts)
You dont need to bother about assigning preferred layout, android device select the layout which is most suitable for their screen. My answer seem to be extra work but its most preferrable if you want to have consistent view on different screen size. Read documentation.

Related Links

How to change ListView Item's background when onLongClick if adapter extends CursorAdapter
where is the proguard mappings.txt file generated when using JACK?
android: how can I get alphabetic name of SMS sender?
How to create a Fragment over the Viewpager in android?
ViewPager obj is null even though it initilized correctly and also present in the defined layout xml
Button On X & Y coordinates of Image
How can fix cpu doesn't support required features (vt-x or svm) for AMD CPU
Socket.io client in android connection with HTTPS protocol failed?
findViewById() method returning null object on some devices
RecyclerView swipeToDismiss Only partial row to be swiped with delete button
Share image on Twitter with TweetComposer?
How to implement Google AdMob mediation in Unity 5.3.5
How to animate items reordering in RecyclerView with StaggeredGridLayoutManager?
sending Image through GCM
getMap() is null in SupportMapFragment in gogole map in andorid fragment
onclick of one button calling functions of two other buttons simultaneously in android

Categories

HOME
delphi-7
eslint
codenvy
c99
datastore
can
dojo
hpc
opengl-3
barcode
accessibility
little-proxy
endeca
java.util.logging
cmdb
naivebayes
intercom
onedrive-api
renjin
altera
event-sourcing
asciidoctor-pdf
postscript
handler
wcag
datastax-enterprise-graph
bioinformatics
custom-controls
database-comparison
mnist
linq-to-objects
opensmpp
signals-slots
avcapturedevice
drupal-theming
monkey-testing
libgphoto2
fclose
datamaps
flac
rxtx
pure-css
custom-lists
centrifuge
jquery-jscrollpane
pre-build-event
spreadjs
fink
cycle2
phpgrid
gocql
wiredep
rate-limiting
skspritenode
dnssec
fail2ban
android-broadcast
actionfilterattribute
document-repository
theos
entry-point
ora-00904
reflector
live555
qscrollarea
multitasking
light
solace-mq
inputmismatchexception
hidapi
kaleidoscope
windows-98
http-status-code-410
correlated-subquery
boost-signals
inkcanvas
azman
filemerge
commerceserver2007
metaweblog
folding
visualj#
google-wave
complex-event-processing
firefox-3
soappy
httpcookie
change-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App