I am currently trying to change the height of the default MasterDetailPage using the material design with FormsAppCompatActivity.
Basically I got the custom renderer to work, but I am trying to resize it dynamically based on toolbar size. The reason being is that different devices have different sized toolbars. Furthermore, I got the resizing to work but the black shadow that comes with the MasterDetailPage stays in place and does not seem to pass through the AddView function.
bool firstDone;
public override void AddView(Android.Views.View child)//Android.Views.View
{
var padding = child.GetType().GetRuntimeProperty("TopPadding").GetValue(child);//tried padding but did not work
if (firstDone)
{
LayoutParams p = (LayoutParams)child.LayoutParameters;
//p.TopMargin = padding;
p.TopMargin = 200;// Need this to be dynamic for different devices
base.AddView(child, p);
}
else
{
firstDone = true;
base.AddView(child);
}
}
Related
I try to achieve the same behaviour of a floating label text as the TextInputLayout class already does but for a different purpose
I got everything working except the x translation of the textview. I don't know how to shift the correct amount of pixels.
It moves up correctly and shrinks down correctly but does not move straigh up because the center for scale is in the middle of the text view. But I want the text view do move straigh up. So my intention was to calculate the length of the text also scale this with the scale value and divide this by 2 (left and right). This does not work. Any ideas how to achieve this no matter the text length?
private void triggerAnimation(boolean fadeOut) {
if (fadeOut) {
float xTranslation = b.tvHint.getPaint().measureText(tvHint.getHint().toString())*0.6f/2;
tvHint.animate().translationY(-tvHint.getHeight() * 0.28f).translationXBy(-xTranslation).scaleX(0.6f).scaleY(0.6f);
} else {
tvHint.animate().translationY(0).translationX(0).scaleX(1f).scaleY(1f);
}
}
Okay it turns out that it is possible to change the coordinates pivot point so this will exactly reproduce the floating label
private void triggerAnimation(boolean fadeOut) {
if (fadeOut) {
tvHint.setPivotX(0);
tvHint.animate().translationY(-tvHint.getHeight() * 0.32f).scaleX(0.7f).scaleY(0.7f);
} else {
tvHint.animate().translationY(0).scaleX(1f).scaleY(1f);
}
}
I have problem similar to this linkbut reproducing only in lollipop and above versions.
Also am using the same tutorial for my implementation.
Somehow using the below code, i am able to remove the square shadow using below code:
Button fab = (Button) findViewById(R.id.fab);
//Outline outline = new Outline();
//outline.setOval(0, 0, size, size);
//fab.setOutline(outline);
ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {
#Override
public void getOutline(View view, Outline outline) {
// Or read size directly from the view's width/height
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
outline.setOval(0, 0, size, size);
}
};
fab.setOutlineProvider(viewOutlineProvider);
But using above code, I am again getting a weird (half circle) shadow on the top of floating action button, like this:
Also the code is removing the shadow n I dont want to remove that.
I had the same problem as you and solved by adding this:
app:borderWidth="0dp"
I have an activity that hosts a fragment, and several others.
This activity already has fitsSystemWindows=false so that it will extend it's boundaries towards the very bottom of the screen, I am hiding the Navigation Bar btw.
The problem is, it has a fragment that has a RichEditor view inside it which means users should be able to put multiple lines of text inside that fragment. SO I made that fragment fitsSystemWindows=true so that when users start clicking on the RichEditor and types, the adjustResize flag, which I have set in the styles, will fire up and allow the user to scroll the page.
It resizes and allows the user to scroll yes.
The only problem is, when the fragment resizes, it gets additional padding on the top and bottom and since I have a custom toolbar on the main activity, it is very awkwardly visibly being added on screen. The funny thing is, the top padding is exactly the same as the height of the device's status bar and the bottom padding is exactly the same as the height of the Navigation Bar.
I tried making the clipToPadding attribute in the fragment's layout into true and false but it does not stop the fragment from getting the additional paddings. I also searched around but I can't get anything useful to get around this as most of the questions I encounter are about how to ALLOW the resize to happen and not anything about how to remove or stop the padding.
Is there even any way to know when the fragment has been resized or the resize has been triggered? If ever I can use that listener to remove the additional paddings as needed.
Any thoughts on this?
EDIT
I already tried putting fitsystemwindows=true in the main activity, but it gets some padding on the bottom for the navigation bar. And I need the activity to fill the whole screen as the navigation bar is hidden
I have solved this by following Matej Snoha's comment. This method attaches a listener to the fragment and when it sees the heightDifference, which is the size of the keyboard as well, is more than the height of the navigation bar, it puts a padding to the bottom of the view thus allowing it to scroll while the keyboard is open.
public class FragmentResizeUtil {
public static void setListenerforResize(final View root, Fragment fragment) {
final int navigationbarHeight = getNavigationBarHeight(fragment);
root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
Rect r = new Rect();
root.getWindowVisibleDisplayFrame(r);
int screenHeight = root.getRootView().getHeight();
int heightDifference = screenHeight - (r.bottom - r.top);
if (heightDifference > navigationbarHeight) {
root.setPadding(0, 0, 0, heightDifference);
} else {
root.setPadding(0, 0, 0, 0);
}
}
});
}
private static int getNavigationBarHeight(Fragment fragment) {
Resources resources = fragment.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}
}
I need to position a TextView the way its baseline is 20dp from the bottom of the container.
How can I achieve this?
The layout with bottom margin or padding produces the same result.
I would like to make the text 'sit' on the purple line.
When I write 'sit' I mean, the 'wert' should touch the line, not 'q...y'.
The padding / margin is equal to the purple square size:
If you still need it, I wrote custom method, to not create lots of custom views. It works for me with TextView:
public static void applyExistingBotMarginFromBaseline(View view) {
final int baseline = view.getBaseline();
final int height = view.getHeight();
final ViewGroup.MarginLayoutParams marginLayoutParams;
try {
marginLayoutParams = ((ViewGroup.MarginLayoutParams) view.getLayoutParams());
} catch (ClassCastException e) {
throw new IllegalArgumentException("Applying margins on a view with wrong layout params.");
}
final int baselineMarginValue = baseline + marginLayoutParams.bottomMargin;
marginLayoutParams.bottomMargin = baselineMarginValue - height;
view.setLayoutParams(marginLayoutParams);
}
You can apply it when view is measured already, so like this:
final TextView title = (TextView) findViewById(R.id.title);
title.post(new Runnable() {
#Override public void run() {
Utils.applyExistingBotMarginFromBaseline(title);
}
});
Also you can use databinding framework and write your own custom BindingAdapter with a bit customized method, to use it from xml.
Your problem is not the padding/margin referenced to the parent, I think is about your font, I recommend you to change the fontFamily:"yourStyle"
even worst you have to re-difine your own font style which is explained here Custom fonts and XML layouts (Android) or Set specific font in a styles.xml
In Android 2.3.x (and maybe previous versions?) when working with any scrollable Views, like a ListView or ScrollLayout, etc, when you reach the top or bottom of the list, a orange gradient appears to indicate that you are at the top or bottom of the list and can't scroll any farther. The gradient gets bigger as you try to scroll farther off the screen. I don't know what the name is of this type of widget in the SDK.
Anyways, how to do I alter it, change colors, get rid of it, etc?
ListView.setOverscrollHeader(Drawable drawable);
ListView.setOverscrollFooter(Drawable drawable);
Have a look at this
change gradient colour at end of ListView
Override setOverScrollMode method
#Override public void setOverScrollMode(int mode) {
if (mode != OVER_SCROLL_NEVER) {
if (mEdgeGlowTop == null) {
final Resources res = getContext().getResources();
final Drawable edge = res.getDrawable(R.drawable.overscroll_edge);
final Drawable glow = res.getDrawable(R.drawable.overscroll_glow);
mEdgeGlowTop = new EdgeGlow(edge, glow);
mEdgeGlowBottom = new EdgeGlow(edge, glow);
}
} else {
mEdgeGlowTop = null;
mEdgeGlowBottom = null;
}
super.setOverScrollMode(mode); }