I have list of images added in a LinearLayout
+------------+
| Image 1 |
+------------+
| Image 2 |
+------------+
| Image 3 |
+------------+
I want every 2nd image to get Displayed above 1st and 3rd Image.
For that I have set Bottom Margin of Image 1 to -10 pixels so Image 2 overrides Image 1 and it works, but this same logic does not work for Image 3, Image 2 does not override Image 3s Top portion, as i have given -10 top margin for the Image 3.
I have also tried bring_to_front for Image 2 but it does not work.
How Should i get it working.
Thanks,
PP.
FrameLayout will be an ideal choice for such a case. It allows z-ordering of child views and will stack all the view over one another. Using view#setVisibility(...) you can toggle visibility of your views to get the desired effect.
use framelayout(it is like div tag in html)
links:
http://developer.android.com/resources/articles/layout-tricks-merge.html
http://android-pro.blogspot.com/2010/02/frame-layout.html
Related
I would like to have a background on my app that changes color depending on a given number. Let me elaborate some more. For example, I pass the number 40 out of 100, 2/5s of the screen should be x color, and the other 3/5s should be the other color. Here are two little diagrams:
40 / 100 40/60
+---+ +---+
| | 3/5 not filled in | | 1/3 not filled in
| | |...| 2/3 filled in
| | |...|
|...| 2/5 filled in +---+
|...|
+---+
So I was thinking I could go about making a dynamic background (giving a certain number) by drawing in the shapes. The problem is, I am not exactly sure how I would go about doing this. Where do I place the code to draw the shapes, and how exactly would I insert them into my XML file in the correct place (I already have a static color background that is up in my XML)?
Ok, you need to create an activity with two Linear Layouts. The width attribute will be set to match_parent and the height to 0dp. You will then be able to set the height with a layout weight of X %.
As an example, those layouts split the screen 25% 75% :
<LinearLayout
layout_weight="1"/>
<LinearLayout
layout_weight="3"/>
Give them an id to change values programmatically (weight and background color).
You can do it this way :
LinearLayout top = findViewById(R.id.top);
//Third Param stands for weight
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 1.0f);
top.setLayoutParams(param);
top.setBackgroundColor(Color.BLUE);
I have a LinearLayout that contains multiple ImageButtons and TextViews. Something like this:
+---------+-----------+-------------------+-------+ <- LinearLayout
| i | i | text here | i |
+---------+-----------+-------------------+-------+
These items are hard to tap. I want to increase their tappable area. It seems as if TouchDelegate is the proper way to do this.
However, view.getParent().setTouchDelegate(new TouchDelegate(r, child)) is a 1:1 mapping, not a 1:Many mapping. So how would one solve this problem when a View has multiple children that each need to be tappable beyond their bounds?
Say we have the below vertical LinearLayout (WRAP_CONTENT on both layout width and height) with two childs Button with varying height.
{ LinearLayout
* empty space *
| |
| Button 1 |
|__________|
|Button 2| }
Why animating Button 1 "y" using ObjectAnimator, producing this:
{ LinearLayout
| |
| Button 1 |
|__________|
* empty space *
|Button 2| }
hence leaving a space there instead of moving Button2 below Button1 as well?
As for the code (nothing fancy): ObjectAnimator.ofFloat(button1, "y", delta).start();
I tried using ValueAnimator (with setY in OnAnimationUpdate() and then upon seeing the same thing,
Setting LinearLayout to invalidate during OnAnimationUpdate() also did the same thing.
tried with TranslateAnimation with fillEnabled and fillAfter being true. Both still producing this behavior.
What am I missing here? I have used LayoutAnimation but so far, I only used to animate them if a child is added or removed. Not if their bounds change.
Can anyone clue me in to the right method/terms here (or the correct way to achieve this effect)?
Note that I also actually wanted Button1 to be clipped by the parent container, if I animate beyond the parent bounds (though I not sure if it makes any difference for Button2). English isn't my first language so pardon the grammar or terms. Thanks.
My problem is that i have one ImageView with my main image (fill the screen) and then i create another one ImageView which is smaller one, dragable and the image has transparent background.
I would like then after the positioning of the smaller ImageView to be able to create one image from this two as i see it on screen. My recent tries i have manage something like this but i have problems with the second image scaling,transparent background and positioning.
[update]
Here is my code. Using this i achieve retaining transparent background but the positioning of the image is wrong i cannot get the correct current position of the position of the second image view. Also, the second image scaling/quality is really bad.
Bitmap cameraImage = ((BitmapDrawable) photoView.getDrawable()).getBitmap();
Bitmap myIcon = ((BitmapDrawable) ( temp).getDrawable()).getBitmap();
myIcon= myIcon.copy(Bitmap.Config.ARGB_8888,true);
cameraImage =cameraImage.copy(Bitmap.Config.ARGB_8888,true);
Canvas canvas = new Canvas(cameraImage);
Rect r=canvas.getClipBounds();
r.left=0;
r.top=0;
r.bottom=r.bottom/2;
r.right=r.right/2;
canvas.drawBitmap(myIcon,null,r,null);
photoView.setImageBitmap(cameraImage);
[update]
The frame is my base Image View and the stars is the second Image View. When the second Image View has a final position lets say the position on the example, I would like to make a bitmap containing these two images. (maintaining transparent background to the second one)
-----------------
| |
| *** |
| *** |
| *** |
| |
| |
| |
| |
-----------------
Thanks,
Adamos
I used this code snippet which takes the screenshot from the parent view of the two images views.
parentView.buildDrawingCache();
Bitmap cache = Bitmap.createBitmap(parentView.getDrawingCache());
photoView.setImageBitmap(cache);
parentView.destroyDrawingCache();
Thanks #hypd09.
I have a UI Design from my designer, and it exists of a background map with several buttons on it, positioned non-linear all over the map. Currently I position them in a RelativeLayout that is as large as the map, and use margin-left and margin-top etc in dip.
This works ok, but I also need to account for users with very small screens, that cause the map to scale down. My relative layout scales with it, but the margin values ofcourse not.
So I am wondering, how should I do this? I would prefer to layout these buttons using percentages like
left="30%"
top="50%"
Is there anything in Android that makes such a thing possible? Otherwise I have to come up with a custom layout class for that.
Visual Representation: (Ofcourse they don't actually are on 6 lines, and partially overlap in x or y position). It's actually a real (abstract) map of a building with location markers that you can press as buttons.
-------------------------
| x x |
| x |
| |
| x |
| x |
| x x|
-------------------------
Here is a complicated way that does not require a custom ViewGroup. Suppose you want a button at left 30%, top 40%
FrameLayout
View with background, match parent
LinearLayout orientation=horizontal, match parent
View layout_width=0dp, layout_weight=30, height=match_parent
LinearLayout orientation=vertical, width=0dp, weight=70, hieght=match
View layout_height=0dp, layout_weight=40, width=match_parent
FrameLayout layout_height=0dp, layout_weight=60
Button
I use Dimension resource files put in the relevant layout- buckets so I can change margins/paddings/sizes depending on device size.
(http://developer.android.com/guide/topics/resources/more-resources.html#Dimension)
(Storing dimensions in xml file in Android)