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

Load more data from Json in RecyclerView on Android
java.lang.IllegalStateException: Could not execute method for android:onClick
Log events Firebase Analytics for Android
edit apk decompiled code
How To Get A Part Of String?
How to prompt the user to choose default navigation application
Device specific bug with CompassOverlay?
Is it okay to use the same layout for two different activities?
Android: Variable has two states
Android TV | How to Center ListRow Items within a parent view (HorizontalGridView)
Is there any way can let greenDAO support android data-binding now?
how to get a boolean value of checkbox whether it is checked or unchecked- android studio?
Android. Gradle build error: Error parsing XML: not well-formed (invalid token)
Surface Texture object is not getting the frames from a Surface Class
Android ActionBar API, getSupportActionBar() and setDisplayHomeAsUpEnable meaning?
How to get package name of any application after successful installation in android? [duplicate]

Categories

HOME
android
sonarqube
localization
awk
developer-tools
object
jmx
interface
themes
jelastic
package
graphics
can
mips
parameters
interpolation
missing-data
title
syntaxnet
octave
scrolltop
identity-management
mapstruct
jmp
nim
topology
selinux
ag
googlebot
gulp-watch
pchart
short-url
roundup
flooding
mat
outliers
apktool
failover
magento-1.8
panoramas
zend-debugger
utorrent
sql-server-2000
playstation-portable
rselenium
sammy.js
reactjs.net
processwire
sharepoint-workflow
reactivekit
timing
cin
jvmti
dcmtk
portforwarding
parser-generator
android-ibeacon
ssrs-2014
knime
mesosphere
dotnet-httpclient
identification
er-diagram
seq
mach-o
parfor
jodd
rspec2
gcloud-ruby
ikiwiki
yajsw
thread-sleep
atan2
pax-exam
.bash-profile
sql-server-data-tools
botan
teamcity-9.1
ms-access-2000
entity-framework-4.3
bcache
punycode
wcm
codeplex
buffering
maven-scm
openargs
spring-3
inputmismatchexception
isqlquery
unit-of-work
cascadingdropdown
apache-abdera
idn
redis-py
dajaxice
appjs
gobject-introspection
screen-size
xcelsius
mysql-error-1205
automationelement
mbeans
dataform
diagrams
delimited-text
non-clustered-index
zend-rest
scrollbars
fault-tolerance
change-management
commercial-application

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