I try to make an app but I have an issue with the background.
The above image shows what should look like the app. Every rectangle of color is a fragment and the red one already have the correct part of the background. But now I try to figure out how can i make the green rectangle background respect this rules :
Image width needs to match parent
The image needs to keep his ratio
Image need to "stick" the bottom (in that way the upper part shows in the red rectangle won't appears in the green one)
In the green fragment I have a ConstraintLayoutand an ImageView like above :
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ss_background_blur"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
The #drawable/ss_background_blur is my PNG image.
Thx
As Neo Shen pointed out in the comments, the only thing you need to do is set the background property of the container element to the drawable resource (the image).
If you have an Activity which only contains three Fragment elements, then you can set the background of the main Activity layout.
You can see and clone a quick demo I put together here:
https://github.com/sipox11/full-background-android-app
This is the result:
Note: I did it very quickly so obviously the tabs are not real tabs and the top bar is not a real nav bar, but you get the idea.
In this case the background image is actually below the tabs area, but if you want it to start on top of it, you can wrap the top and middle fragments within a LinearLayout and set the background image to that container.
Hope it helps,
Cheers.
Set the background of the rootlayout to green and add android:layout_margin="2dp" to the imageview .
Hope this helps.
Related
Im working on an android app were you can setup your own Ring.
Now I want to give the user a preview of the ring, when they selected multiple rings.
Here a preview of how it should look like
The setup of how i thought to make it is this:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="5dp">
<ImageView
android:id="#+id/generator_ring_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e7e7e7"/>
<FrameLayout
android:id="#+id/generator_ring_addon_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</FrameLayout>
I'm going to add the addon rings programmatically by just creating a new ImageView in the code.
Now the hard part of this is to place the image over the other ring, and have the view the same on every screen size..
Is ther anybody who can help me getting the correct code for placing the image on the correct position on every screen size?
thanks for reading
EDIT:
the moment I am selecting the addons rings the Base Rings is already visible, so I can get the height of the image
User Paint API: https://developer.android.com/reference/android/graphics/Paint.html
https://developer.android.com/reference/android/graphics/Canvas.html
Like that you can add whatever pictures you want, programatically, move them, even create animations if you want.
Also you will have just a view, which contains the canvas. So no need to have convoluted FrameLayouts into FrameLayouts.
Example on how to draw images on a canvas.
draw object/image on canvas
Using canvas you can get (x,y) coordinates of the ring.
First create canvas with ring image and than use canvas.draw() to draw another image on base image.
I'm new to Android and discover lots of things. But now I'm quite stucked.
I want to make a hexagonal board game, with tiles. I found many tutos and finally decided to draw as mush hexagons as I want to.
I created a 'Hex' class extending from View, add some variables and so on. Here is what I put in my main XML layout:
<flocoolb.app6.Hex
android:layout_width="wrap_content"
android:layout_height="wrap_content"
flocoolb:r="50"
android:id="#+id/h01"/>
<flocoolb.app6.Hex
android:layout_width="wrap_content"
android:layout_height="wrap_content"
flocoolb:r="50"
flocoolb:x="75"
flocoolb:y="43.30127"
android:id="#+id/h02"/>
<flocoolb.app6.Hex
android:layout_width="wrap_content"
android:layout_height="wrap_content"
flocoolb:r="50"
flocoolb:x="150"
android:id="#+id/h03"/>
r=size, x and y are offsets on canvas.
Here is what I get on my activity:
Main activity screen
But now I want to select single Hex. For example I want to select to top left one, or the bottom right one. I add OnClickListener on each of them, but actually the size of the view is the whole screen.
For example, if I change the background color of the view, it change that color on the whole screen. Is it possible to have the view limited to the drawn lines?
I hope you will understand what I mean.
Many thanks :)
Although,I don't understand you very much.But I suggest you to override onTouch Method of your view.And implement your function in onTouch method.
Goal: A highlighted section of an image (the image covers the whole screen). The rest of the screen needs to be faded out.
Example
So far I've got the fading working using the foreground of a FrameLayout and placing the image as the background of a RelativeLayout within the FrameLayout. The solution I'm thinking is that I need to create 2 Drawables and merge them into one that FrameLayout Foreground can consume.
I've also been reading a bit up on PorterDuff, but I think that may be overkill for what I'm trying to achieve.
The fade functionality is working fine, but the source of the fade with transparent section is not.
I suggest that you have the original image in an ImageView on top of it place 4 views which are partially dimmed and that's it!
With some basic math you can know the sizes for each view, and using RelativeLayout will allow you to easily place them on the screen.
Good Luck!
P.S. I've attached a sketch to illustrate what I'm suggesting.
I want to resize an ImageButton, but when i change the size of the ImageButton with the mouse on graphical layout on eclipse, and leave the left mouse button, the ImageButton returns to its original size. I have already tried this:
android:layout_width="50dip"
android:layout_height="50dip"
But it doesen't work for me.
The problem is that this button should be a hidden button, so i cut a part of background of my app to do this, but when i put this part on my app it is larger, so everyone can see the difference. The problem is that the app resize my background image to make it compatible with the screen.
The use of dip has been replaced by dp, which stands for Density Pixel.
Documentation on dp can be found here
Try using just 'dp' instead of 'dip'
"dp" is more consistent with "sp".
I want to code a layout like the following image in xml in Android.
One approach would be to have a RelativeLayout and make a 9 patch rounded rectangle border image, have it as the background around a layout which has the two blue buttons, and then have and EditText overlapping it, with its background set to a red color.
What could be other approaches?
As I understood your question you want to make series of photos ..like Gallery application
you can do it with more option also.
1)this is gallery type application .
so . you can use this basic code :Android Gallery Application
2)If you want to see all the photos in circle this is also possible..
It depends upon your need ..please write in brief you want more...