android


Resize Image Proportionally on Orientation Change


I have a fragment inside an activity that consists of a RelativeLayout, an ImageView and a TextView having following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/avaImage"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="Available"
android:textSize="26sp" />
<ImageView
android:id="#+id/avaImage"
android:layout_width="487dp"
android:layout_height="238dp"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:scaleType="centerInside" />
</RelativeLayout>
This is how I'm setting the image source programatically:
ImageView image = (ImageView) rootView.findViewById(R.id.avaImage);
image.setImageDrawable(getResources().getDrawable(R.drawable.availability_green));
My question is, how can I shrink the image size so it fits in the screen in landscape mode, as well? Image shall be shrunk just enough to have the text appear within the bounds? This is what I want to achieve
Potrait:
Landscape:
Try this code for your images shrunk. its set same image ration with center.
<?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:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" >
<ImageView
android:id="#+id/avaImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/txtLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Available" />
</LinearLayout>

Related Links

Android: OTG Storage notification conflicts with radio c
Layout looks different on devices
Check android device density in html
Is that possible to connect two phones with adb connect?
App using Mobile Android GNSK crashes when identifyAlbumAsync() is called before audioProcessStart()
Get values from multiple RadioGroups
Can't Initialize Google Play Services
RESTful Api or Socket.IO
Android adding image to picture taken with camera
Cannot see any git branches
How to detect if my app was uninstalled? [duplicate]
android- How to animate between view flipper change images
Migrating to Google Maps V2. Neccessary to compile using Google Apis?
bitmap image into Base64(blob), and try to save in mysql error in connection
Insert a sound after a Toast, Eclipse
How to find out that RSS feed is updated?

Categories

HOME
uml
ng-idle
fpga
mysql-workbench
obfuscation
composite-primary-key
pdfbox
frontend
character
teechart
rcloud
drop-down-menu
pega
siddhi
redis-sentinel
plink
docx
gruntfile
modbus-tcp
esoteric-languages
mvc-mini-profiler
html5-appcache
google-picker
cfml
nim
oledb
cgbitmapcontext
custom-post-type
shared
android-maps
underscore.js
angular-translate
gp
uitapgesturerecognizer
testcomplete
google-cast
autodesk-designautomation
dst
mockjax
clickjacking
dynamic-jasper
apic
git-rewrite-history
timing
ideascript
google-data-api
p4merge
tasm
azure-arm
movilizer
plr
ssrs-2014
apollostack
optimizely
puredata
pom.xml
wcftestclient
corruption
page-replacement
magic-draw
jqchart
trigger.io
objectscript
polyline
gets
pacemaker
mta
installshield-2010
dimension
jclouds
nullable
maybe
assertion
iokit
fiware-monitoring
fuelcms
doctype
sha512
git-ftp
snackbar
jquery-forms-plugin
cross-join
beatsmusic
mruby
teaspoon
malformedurlexception
jquery-slider
terminate
file-not-found
c++builder-xe5
gpars
epiceditor
intersect
ilasm
strsep
cac
addchild
isapi-extension
zen
django-piston
fault-tolerance
linfu-dynamicproxy
entitykey
business-model

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