My purpose is to apply a bg to my main view, rotate by xxx degrees and make it repeat in order to fill all the screen, no matter the resolution of the device.
It seems i could make it rotate BUT it doesn't repeat as i wish. I think Android calculate the bg image, then it rotates.
The result is the following. Empty areas on top right and bottom left corners.
and this is the xml generating the bg
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="-20"
android:pivotX="50%"
android:pivotY="50%">
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/cropped_bg"
android:alpha=".20"
android:tileMode="repeat"
android:gravity="center"/>
</rotate>
Can somebody help me?
Related
I am trying to get a gradient inside a rectangle to look like this
The closest I get using following xml is
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="radial"
android:startColor="#color/lightPurple"
android:endColor="#color/lightGreen"
android:gradientRadius="600"
android:angle="270"
android:centerX="1"
android:centerY="0"/>
</shape>
Is there anything I can do to make my gradient go from the top right corner to bottom left corner?
Try android:type='linear' and android:angle='45'.
This would get you more closer to edge-to-edge. Android doesn't provide arbitrary angles for this. The only valid angles are the ones which are a multiple of 45. However as far as I can see, the gradient you require is not actually edge-to-edge and I suspect it to be the one with angle 45.
I am using this example to create splash screen for my android app. But the background image is stretching. Below is the code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimary" />
<item>
<bitmap android:src="#drawable/splash_portrait" />
</item>
</layer-list>
How to proportionately scale the bitmap?
The image you use should be a Vector Image.
Vector Images can resize at will and still retain clarity.
If you use normal images, no matter how you implement it, it will either stretch or shrink depending on the mobile screen.
Is there any xml that i can use to perform something like this ?
I want to have an single ImageView where i show my picture. The picture is "fillparent" that it goes on the whole screen. But i only want to see the pink part normal and all outside the lines i want something like an "alpha = 0.5" or just that it is a little bit less seen than the main.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="120px" android:right="120px" android:bottom="120px" android:left="120px">
<shape android:shape="rectangle">
<solid android:color="#9fffffff" />
</shape>
</item>
I want to put an xml as foreground to perform this. With an shape of an rectangle and an alpha of 0.5 it works exactly the opposite side. Now i just need something like an inverse rectangle or something.
Thanks for your time.
I have defined a bitmap in /drawable/app_background_raw as such:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/actual_png_file"
android:tileMode="repeat" />
Now I want two copies of this defined - one as it is unchanged, and one rotated 90 degerees so that I can use it in portrait mode. I can create the rotated one as such:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="0%"
android:pivotY="0%"
android:drawable="#drawable/app_background_raw">
</rotate>
..but how do I, with least overhead, create an unchanged copy of app_background_raw? I can obviously create another RotationDrawable rotated 0 degrees, but that feels a bit silly. Suggestions?
Update
This was a bad idea for this scenario, as Android seems to scale the bitmap for portait mode before I can rotate, but in any case I'm interested in knowing what the simplest way of creating an alias for a drawable is.
I'm still new to android and i'm having trouble creating a layout with two backgrounds that tile in the x direction but not y.
I've mocked up what I'm trying to create here...
http://img153.imageshack.us/img153/6008/cnbackground.png
So the top section repeats horizontally, then there's a flat creen section in the middle in which I will center my content, then there's some horizontally repeating grass along the bottom.
Has anyone tried to do anything like this before?
Jon
Here's a good simple tutorial on the repeated background image part:
http://androidblogger.blogspot.com/2009/01/how-to-have-tiled-background-cont.html
As far as the layout, I'd go with a RelativeLayout as my main parent layout, and then you'll have three sub-layouts to represent the top, middle, and bottom sections. Use android:layout_alignParentTop on the top layout, android:layout_alignParentBottom on the bottom, and the middle content layout should have the attributes android:layout_above and android:layout_below set to the #+id's of the bottom and top (respectively).
You can mimic repeat-x by using a layer-list as the drawable. You tile bitmap image both x and y and then use an offset solid shape to fill over the repeated y images. Isn't perfect, but will do the job.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap
android:src="#drawable/icon"
android:tileMode="repeat" />
</item>
<item android:top="60dp">
<shape >
<solid android:color="#FF000000" />
</shape>
</item>
</layer-list>