How to make an app's background image repeat
Ok, here's what I've got in my app. It includes a hack to prevent ListView
s from going black while scrolling.
drawable/app_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/actual_pattern_image"
android:tileMode="repeat" />
values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="app_theme" parent="android:Theme">
<item name="android:windowBackground">@drawable/app_background</item>
<item name="android:listViewStyle">@style/TransparentListView</item>
<item name="android:expandableListViewStyle">@style/TransparentExpandableListView</item>
</style>
<style name="TransparentListView" parent="@android:style/Widget.ListView">
<item name="android:cacheColorHint">@android:color/transparent</item>
</style>
<style name="TransparentExpandableListView" parent="@android:style/Widget.ExpandableListView">
<item name="android:cacheColorHint">@android:color/transparent</item>
</style>
</resources>
AndroidManifest.xml:
//
<application android:theme="@style/app_theme">
//
How can I repeat a pattern image to create a background in React Native?
You can't repeat background image like CSS in React Native. But, You can achieve it by iterating the image like
var React = require('react-native');
var Dimensions = require('Dimensions');
var {
Image
} = React;
var RepeatImage = React.createClass({
render: function(){
var images = [],
imgWidth = 7,
winWidth =Dimensions.get('window').width;
for(var i=0;i<Math.ceil(winWidth / imgWidth);i++){
images.push((
<Image source={{uri: 'http://xxx.png'}} style={} />
))
}
return (
<View style={{flex:1,flexDirection:'row'}}>
{
images.map(function(img,i){
return img;
})
}
</View>
)
}
});
Android Splashscreen background repeat pattern
Seems like you are not using <layer-list>
in your drawable. try this code instead.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:src="@drawable/ic_background_blue"
android:tileMode="repeat"/>
</item>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/ic_splash_logo"/>
</item>
</layer-list>
EDIT: Checked the image that you provided and its resolution seems to be too big (2000 x 2000). Possible solutions are scaling the image down manually or make the image background programmatically.
background image not repeating in android layout
Create a copy of grass_bg.xml
for each time you use it (ie grass_bg_2.xml
). This worked for me to assure the tileMode
setting was not lost when the same background is used repeatedly.
Background image will not fit in the whole page in App.css in create-react-app
Basically, background-size: 100% will fill the screen with the image, and crop it if necessary.
I think what you want is to see the whole image. You should use contain for that:
html {
width: 100%;
height: 100%;
background: red url('http://media.gettyimages.com/photos/groningen-city-view- picture-id588880579?s=612x612') no-repeat center;
background-size:contain;
}
Related Topics
Eclipse Error "Adb Server Didn't Ack, Failed to Start Daemon"
Transfer Data Between iOS and Android via Bluetooth
Android Webview Not Loading an Https Url
How to Programmatically Turn Off Wifi on Android Device
Non-Scrollable Listview Inside Scrollview
Display the Current Time and Date in an Android Application
Java.Lang.Illegalargumentexception: View Not Attached to Window Manager
Android Ratingbar Change Star Colors
Notification Click: Activity Already Open
Android Studio - Emulator - Eglsurfaceattrib Not Implemented
Android.Content.Activitynotfoundexception: Unable to Find Explicit Activity Class
Android Startcamera Gives Me Null Intent and ... Does It Destroy My Global Variable
Listview Subobject Clickable Confilct
Cannot Get Folderid That I Just Created on Google Drive