I'm using Translucent Navigation bar by adding below attribute to make my app mobile nav menu looks like some Google apps where mobile nav bar is a bit transparent and content will visible through it.
<item name="android:windowTranslucentNavigation">true</item>
But my output is it
I don't want my views to go under it. I just need it when there is More content to scroll on screen like when there is a scrolling activity or in recyclerview. But at the end I need my activity views to not overlap by it.
Any suggestions please...
You may need to apply insets to have space between bottom of the device and navigationbar. RootView is the top layout on xml file.
rootView.setOnApplyWindowInsetsListener { view, insets ->
recyclerview.run {
setPadding(paddingLeft,paddingTop,paddingRight, insets.systemWindowInsetBottom)
}
insets
}
With this snippet you will have transparent navigationbar but your RecyclerView will always be above navigationBar.
And add
android:clipToPadding="false"
flag, this works with RecyclerView, and other scrollable views i guess.
You can check out this medium article or Chris Bane's tivi app to get familiar with insets.
Also put an example on github
What you could try for a static view is:
android:layout_marginBottom="?android:attr/actionBarSize"
If in a ScrollView this obviously won´t work but you can still try to play around wiht different layers inside the xml and fit a margin or padding if needed.
Otherwise it might be helpful if you post your xml file to actually see what you try to implement.
It is possible in both ScrollView and Recyclerview.
If there is scrollview in your Xml file then you should create
two other layout(ex: LinearLayout1 as Scrollview child Layout and
LinearLayout2 as LinearLayout1 child Layout) as a child layouts and
set bottom margin in the Secode child layout(LinearLayout2) same as
your bottom navigationBar height.
Well, here is the example how you can get bottom navigationBar height.
public int getNavigationBarHeight()
{
boolean hasMenuKey = ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey();
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0 && !hasMenuKey)
{
return getResources().getDimensionPixelSize(resourceId);
}
return 0;
}
Note: The height of the navigationBar is in px. So, you have to set margin of your child layout in px.
For Recyclerview, you can give bottom margin(RunTime) of parent
layout in adapter class for the last item of the recyclerView
same as navigationBar height.
Example:
if (position==adapter_dueModelList.size()-1){// the list item
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
params.setMargins(0, 0, 0, 132);//give margin same as a navigationBar height.
((ViewHolder) holder).linear_layout.setLayoutParams(params);
}
Related
How can I create a half-expanded toolbar? Something like that WhatsApp profile page.
I've tried scrollBy and scrollTo, but they don't seem to work.
Even dispatchNestedScroll, onNesterScroll and onNestedPreScroll don't seem to work.
I managed to solve this problem by adapting this answer: https://stackoverflow.com/a/34920495/5369519 and using the following code:
nestedScrollView.post(() -> {
int appBarHeight = appBar.getHeight()/2;
nestedScrollView.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
nestedScrollView.dispatchNestedPreScroll(0, appBarHeight, null, null);
nestedScrollView.dispatchNestedScroll(0, 0, 0, 0, new int[]{0, -appBarHeight});
});
This simulates scrolling halfway down.
Just using NestedScrollView.scrollTo() is not enough to trigger the scroll events for the parent.
To create the collapsing toolbar, CollapsingToolbarLayout integrates with AppBarLayout, CoordinatorLayout, Toolbar, and a scrollable content view, such as RecyclerView
This is what I'm hoping to achieve:
Step 1: Click on the Green Button to open View1.xml on the ViewPager. (Works)
Step 2: Click on the Orange Button to open SubView.xml on the ViewPager. (Doesn't work)
So, I have set the onClick event for the orange button the following:
public void openForm(View view) {
ViewGroup item = (ViewGroup)findViewById(R.id.vp_horizontal_ntb); //this is the view pager
View child = getLayoutInflater().inflate(R.layout.activity_post_form, null);
item.addView(child);
}
Results:
Nothing. Nothing happens.
If I switch viewpager for linearlayout it opens (and breaks tab navigation). What I wanna do is open it on the viewpager, so it looks and behaves as if it's on a tab, until it's removed by clicking on another tab.
I also thought about putting a linear layout there and make viewPager gone while the linearLayout is set to visible. But I feel like there's a better solution than this.
In my App i have two popupWindows. I open them both like..
aboutView = getLayoutInflater().inflate(R.layout.layout_about, null);
aboutWindow = new PopupWindow(aboutView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
aboutWindow.showAtLocation(findViewById(R.id.lay_main), Gravity.CENTER, 0, 0);
Both layouts are set to match_parent, where one of them opens just fine.
The second starts on the screens top, hidden below the Android status bar.
The reason must be within the layouts itself.
When i copy the good and just rename it..it shows up just fine.
When i change the content (add image views etc..), it's screwd up.
Is there a known reason?
EDIT:
I just figured out that i have an ScrollView in my layout..as soon as i remove that or change it to e.g. an RelativeView, thats when it slips under the status bar.
On Android, how programmatically I can change the ProgressBar, to show itself on different heights, as seen and work using the XML :
<ProgressBar ..... android:layout_marginBottom="100dp" ?
When I change on android:layout_marginBottom=”xxxdp” it change it location, in deferent height. But it fixed. I need to move it up and down during runtime,
I need to show this ProgressBar in different location from listView Bottom during application running.
The layout_* attributes refer to the parent layout's LayoutParams in code.
If the parent layout params is of type ViewGroup.MarginLayoutParams e.g. the parent is a LinearLayout or a RelativeLayout, you can modify it and call requestLayout() to have the changes take effect:
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)progressBar.getLayoutParams();
params.bottomMargin += 123;
progressBar.requestLayout();
If ProgressBar's parent is RelativeLayout, use RelativeLayout.LayoutParams.
LinearLayout.LayoutParams lp = progbar.getLayoutParams();
int margin = lp.marginBottom;
margin += your_value;
lp.setMargins(0, 0, 0, margin);
progbar.setLayoutParams(lp);
I am creating an app that uses a custom camera. The idea is that I just define a Framelayout in my xml file and them programmatically add the SurfaceView (this is the camera preview) and some other ImageViews (e.g. a shutter button, flash button...)
I managed to get the SurfaceView working but now I am a bit stuck. I want to add multiple imageview to the frame layout, but how can I get them setup correctly. I am referring to their location in the frame layout.
Can I create a relativelayout and add that to my frame layout programmatically?? If so, how do I do that?
Please, can anyone give me some tips??
Thanks!
FrameLayou can have only one direct child. You can try this
SurfaceView surface = .....;
FrameLayout frame = findViewById(R.id.frame);
RelativeLayout relativeLayout = new RelativeLayout(this);
frame.addView(relativeLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
relativeLayout.addView(surface, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// here you should add your images to relativeLayout