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

Need UI Watcher Sample Code
Save a Layout with Changing values in a loop on sdcard in android
Android Identify Valid Google Referral URL
MapFragment and Mapview API v2
Splash while native is loading in android
Line not visible on canvas
Theme switch has caused buttons to stretch?
I looked for this Null pointer exception because of getTag with Spinners and it has been a while
FragmentPagerAdapter don't want page titles
Want to add verification points in android mobile phone apps using Perl
Android: Coordinate SounPool and TTS
Android draw9patch tool
Get user/owner profile contact URI and user image with API 8 onwards
Custom Listview Adapter not working
Jar signer, Unable to open jar file?
where clause in contentProvider's query in Android

Categories

HOME
android
cheerio
jelastic
rendering
opendj
settings
computer-science
categorical-data
google-chrome-app
comsol
qsqlquery
libusb
azure-iot-hub
wolframalpha
foreign-keys
enterprise-miner
solrcloud
sar
guzzle
gulp-watch
string-concatenation
strongname
beautifier
syntax-highlighting
ms-access-2003
iis-express
anki
quickfixj
fstream
joomla2.5
installscript
swagger-php
imagenet
dm-script
railstutorial.org
css-position
visa
claims
chronicle-map
oim
x++
rserve
google-cse
aquamacs
appdomain
oracleclient
ngmaterial
skin
cup
quicktime
greatest-n-per-group
windows-azure-queues
mta
lua-telegram-bot
angular-ui-typeahead
nss
boost-serialization
qbxml
mobiledoc-kit
asyncdisplaykit
assertion
xvim
sapscript
slash
wso2greg
ansi
nsurlsessiondatatask
aspectj-maven-plugin
cakephp-2.7
beatsmusic
jbake
iiop
entry-point
machine-instruction
psr-4
nsmenu
angular-carousel
lambda-architecture
reflector
ios8-extension
spring-remoting
cfcache
jammer
mbunit
dtmf
modular
unit-of-work
traceability
chart-director
joomla3.1
curb
android-loadermanager
qi4j
fragmenttransaction
kqueue
jsr286
google-maps-mobile
mtu
commerceserver2007
ajax-polling
murmurhash
data-mapping
wcf-instancing
visualj#
application-planning
unmanagedresources
pnrp

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