Shift layout down by using paddingTop and device Height - android

I have a layout which I want to slide down, but not entirely so you can still see a "scroll back up" text. So how I want to do this:
get the dimensions of the device. Put paddingTop = screenHeight - 7dp (for the text). Is this possible? I've tried with layoutparams too but then everything in the layout resized, including the "scroll back up" text.
What is the best way of doing this?

You could use Animation to accomplish this task.
A working example using animation with ViewFlipper can be found here.

Related

Increase Relative layout width to the left and to the right

I want my RelativeLayout to spread with both direction left to right and right to left
I've made several research and I've got a answer for left to right spread Animation with ValueAnimator.
ValueAnimator.ofInt(0, width);
but when I reverse it then it disappears. It works same as
ValueAnimator.ofInt(width,0);
I've already tried .reverse() function. But this was not a solution.
Is there any idea for Right to Left Animation? Or Do I have to Use a other solution with xml.
But I want to do with dynamically way as much as possible.
Edit :
I've made more research and found some way.
Increase Android button's width from right to left
This is exactly what I want to be worked. But this is something on ViewGroup...
Increase LinearLayout width from either right or left
Try this trick
This Logic is like moving left and the width
With this Logic I solved my problem
I used ValueAnimator and animation is from onAnimationUpdate value
params.leftMargin = xParams - (Integer)animation.getAnimatedValue() + width;
params.width = (Integer)animation.getAnimatedValue();
will do the trick

Resizing only the height of CardView also changes the width

I currently have a recycler view that has a list of CardViews.
When I click on the card I want to be able to expand the card (change only the height). This is working fine by setting the new height to the card with an animation.
The problem is that when I click to expand the card, the width also shrinks to less than half the width of the screen. If I scroll the view away and come back the width is set correctly. Every time I try to expand the height, it expands to the right size but the width shrinks.
Is there something that I'm supposed to do to expand/collapse a card in a recycler view and not have this side effect of also resizing the card width?
I tried only setting the height in a valueAnimator and that works for the expansion.
I tried to set the width programmatically at the end of the animation to match parent but that has no effect.
for better solution pls share code with us, until that.
check your xml codes for any Wrap content value for width.
It will solve your issue.

Can android padding be made to be not clickable?

EDIT: Answer found through Emil's comments. Code ended up like this:
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
view.setLayoutParams(params);
Thanks all :D
I'm currently writing an Android application and I have a dynamically created tree which displays ImageView elements within it. However, to arrange these images I've used padding left to line them up correctly, dynamically changing how the padding is calculated so that everything turns out evenly. However when I do this, the padding covers up some of the images to the left, and even though you can see the images behind this padding, when you click on that image, it will evaluate the image who's padding is being used (the furthest left element). I'm basically wondering if there is a way to programatically set something that does what padding does to images but isn't clickable? Margins would make sense, but you cannot set margins on ImageViews.
The tree set up is like this:
-----A-----
--B--C--D--
-E-F----G--
Imagine every letter is an ImageView, dynamically placed with padding. But if I click on B or C, D's code will be evaluated because it's left padding covers B and C. The same goes for E or F, click those, and G will be evaluated. I cannot figure out a different way to place these ImageViews. Any help is greatly appreciated.
Consider replacing your padding with layout_margin property. that way the area that separates the padded view is not considered as part of the view but ratter as part of the layout it sits in.
So use
android:layout_margin="10dp"
or:
android:layout_marginLeft="10dp"
for your needs.

move the screen content to the left outside the screen android

is there a way to move the whole screen content outside the screen bounds, with titlebar and all, on the left for example, i tried
content = ((LinearLayout) act.findViewById(android.R.id.content)
.getParent());
to get the screen content and add a margin to it
FrameLayout.LayoutParams pr = (android.widget.FrameLayout.LayoutParams) content
.getLayoutParams();
pr.rightMargin = xOffset;
content.setLayoutParams(pr);
but it doesnt work, the margin appears but the content is not moved just resized to fit the screen, anyone know how to do this the simple way?
you can set the margin in negative(-) values.
for example if your want the layout to move upper use this:
android:marginTop = "-50dip or more u can put"
Are you trying to flip between views? As in, moving that layout off the screen to show another one? If so you should look at using a widget called ViewFlipper which will do exactly as you need. It can also be animated etc.
http://developer.android.com/reference/android/widget/ViewFlipper.html

Positioning items relative to the ActionBar in Android

I used to have an Activity that would use no ActionBar. The layout is a RelativeLayout with width and height simply matching the parent. It allowed users to drag around buttons using parts of this code in the onTouch event:
MarginLayoutParams marginParams = new MarginLayoutParams(v.getLayoutParams());
int left = (int) event.getRawX() - (v.getWidth() / 2);
int top = (int) event.getRawY() - (v.getHeight());
marginParams.setMargins(left, top, 0, 0);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
v.setLayoutParams(layoutParams);
All dandy—the button moves just below the finger and is placed correctly at the position on screen. Now, however, I enabled the ActionBar, and suddenly when clicked, the button moves ~30 pixels below the finger. To illustrate this behavior, here's what I used to have (on the left) and what happens right now (on the right):
I assume this is because the ActionBar now displaces everything by its own height. Of course, I do not want this to happen, or at least correct this, so:
How can I shift the placement in setMargins() according to the actual size of the ActionBar without using a hardcoded value?
How can I prevent the ActionBar from shifting everything in the first place? Put differently, how can I ensure my button is placed relative to the ActionBar's bottom line and directly where the finger points?
This is what I want:
(I used an approach is my code and it works. I am going to tell you the same here)
I think setMargin() is not such a clever thing to use here. Instead you can use setX() and setY() methods.
Whenever one switches over from a full screen activity to the one with Action Bar, one runs into such problem.
You will need to adjust for the Action Bar height. Instead of using getLayoutParams(), use getLocationInWindow() or getLocationOnScreen(). Since getRawX() and getRawY() work with screen positions of the view, these APIs should be used.

Categories

Resources