android


How to animate a wide image (right to left) as the background of my activity?


I need to set my wide image (1800x1201px) as the background of my activity so I can place the app logo and sign in/sign up buttons above.
I tried using a FrameLayout with an ImageView. The animation is working, however the image is not filling the entire FrameLayout height.
Activity
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/splash_base_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="br.com.myapp.app.activities.SplashActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/splash_bg_image"
android:src="#drawable/splash_background"
android:contentDescription=""
android:scaleType="matrix"
android:adjustViewBounds="false"
android:cropToPadding="false" />
</FrameLayout>
Activity Class
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
animateBackground();
}
private void animateBackground() {
final ImageView splashImage = (ImageView) findViewById(R.id.splash_bg_image);
splashImage.startAnimation(outToLeftAnimation());
}
private Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(20000L);
return outtoLeft;
}
}
Here's how it is currently previewed on Android Studio:
I tried setting layout_height both with match_parent and wrap_content, but could not find the right scaleType to make it fill the screen height and create the right to left animation.
UPDATE
I created a larger image (3840x2560) for xxx-hdpi devices and now the preview shows the image the way I need, however when I run the app it has blank spaces on top and bottom.
Also I need to create kind of a "boomerang" animation so when the image has gone right to left it reverses the animation from left to right, and so on.
Updated image:
Change android:adjustViewBounds="false" to android:adjustViewBounds="true" and make its height match_parent and it's done.
Hi can you refer this example Android: proportionally stretch an ImageView to fit the whole screen width while maintaining its aspect ratio

Related Links

Is this normal GC behaviour from support.map.fragment?
How to make the keyboard overlap the form field
Delete Method in sqlite only deleting 1 row in listview
Display and parse images from DB to listview
How to solve an instantiate the map fragment error?
How to /unregister a custom view (from xml) automatically on a bus
How to Parse the JSON response which contains the two arraylist
Adding items to action bar (using ActionBarSherlock)
Automatic count of compiles in Eclipse/Android development toolkit
Show Android Map Markers in ListView
Best way to switch between two fragments
ScrollView a TableLayout inside a TabHost
How to multipart data using Android Volley
SQLite disk IO exception and can't open database exception
How to prevent concurrent streaming
Google Maps not showing up Android

Categories

HOME
service-worker
go
twig
numbers
pascal
soa
mips
nested-if
echo
lanczos
arangodb
dkim
github-enterprise
enterprise-architect
docx
google-picker
sencha-touch
solrcloud
googlebot
perlbrew
sinch
eviews
powershell-ise
rselenium
jett
biztalk-rule-engine
arduino-ide
fiware-cygnus
timing
projects-and-solutions
sim-card
apns-php
railstutorial.org
verifiable-c
azure-arm
skylink
dcmtk
lpsolve
avcapturedevice
dapper-simplecrud
monkey-testing
mongotemplate
ngmaterial
boo
pybrain
universal-analytics
shinobi
bootstrap-tags-input
donations
ziparchive
redbeard-ios
spring-cloud-feign
flex4.6
uicolor
omniauth-facebook
kango-framework
angular-ui-typeahead
tracker-enabled-dbcontext
cda
thread-sleep
rewrite
entity-framework-4.3
procedural-programming
execve
android-cookiemanager
sip-server
contrast
wcm
universal-image-loader
mdichild
template-deduction
mintty
reflector
conditionaltagsupport
notorm
sphinxql
ie8-compatibility-mode
gpars
android-icons
swfobject
sqlclr
robotlegs
joomla3.1
panda3d
vfs
cakephp-1.2
iboutlet
window-decoration
diagrams
eclipse-marketplace
addchild
murmurhash
soappy
change-management
online-storage
commercial-application

Resources

Encrypt Message