I have created BottomSheetDialogFragment and access into my fragment but it not open fully, it shows only small bar in bottom like below
I am using default BottomSheetDialogFragment file without changing anything.
xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="#dimen/list_item_spacing_half"
android:paddingBottom="#dimen/list_item_spacing_half"
tools:context=".ui.SettingFragment"
tools:listitem="#layout/fragment_setting_list_dialog_item" />
Show call function
val addBottomDialogFragment: SettingFragment = SettingFragment.newInstance(10)
addBottomDialogFragment.show(supportFragmentManager, "tag")
Height of BottomSheet depend on child content height So first you should add some child view or content under bottom sheet view. If you using RecyclerView then set adapter with data.
Because your BottomSheet don't have content, You have to add content to it
Your bottom sheet root element should be "Linear Layout" or "Relative Layout" set background to Transparent.
Related
I'm struggled with this for hours looking for solution on google and stackoverflow. Thought that this is some trivial bug in my app but finally made empty project and can reproduce this too. Just run new project and select "Tabbed Activity" with navigation style "Action Bar Tabs (with ViewPager)
Then try to put any widget at the bottom of the fragment's layout. I did this by modify fragment_main.xml and adding:
android:layout_height="match_parent"
android:gravity="bottom"
android:textAlignment="center"
So the whole layout is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity$PlaceholderFragment">
<TextView
android:id="#+id/section_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:gravity="bottom"
android:text="aaaaaaa"
android:textAlignment="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#+id/constraintLayout"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
</android.support.constraint.ConstraintLayout>
In design mode everything looks fine:
But when you run app:
You will see text only when you swipe action bar to hide it:
So it is impossible to set widget at the bottom of the tab's fragment or even match some list/picture to the height of the parent because bottom edge will be always under navigation bar.
Workaround which I found is here:
ViewPager with Toolbar and TabLayout has wrong height
First one is to put AppBarLayout and ViewPager between LinearLayout but then I lose hidding action bar functionality when scrolling ViewPager's content. Second one is add android:paddingBottom="?attr/actionBarSize" in ViewPager but then there is a gap when I hide action bar. Seriously there is no solution for this?
I think this is an expected behavior since the ActionBar gets hidden when scrolling up. In the design mode the text can be shown because it doesn't display the TabLayout. However, when you launch the app, it will inflate the TabLayout and the fragment will go below it. So it's not like the fragment is getting expanded or giving you wrong height.
Imagine putting an ImageView that has a matching height of the visible field (from below the TabLayout to right above the navigation menu). When you hide action bar from there, it will have a gap on the bottom since there's no content to fill up the space of hidden action bar, unless you stretch the ImageView as you scroll up, which will result in wired stretched image :/
One possible solution I can think of is, if you want to add a view on the bottom of the fragment, I will set the actionbar padding to the view and when I scroll the screen, I will adjust the padding depends on the scroll offset so that I can always be on the bottom.
I am very beginner in android. I am trying to design a screen, in which I had selected the navigation drawer template when I created the project. So the basic things required are in place, like toolbar on the top and a drawer menu icon on the left. Now i want to place an imageview below the toolbar and a list view below the imageview. I am using the following xml for the layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
<ImageView
android:id="#+id/sliderTempImageView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="#drawable/slider_image1" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
But the image covers the toolbar and fit the entire screen, even I had given fixed height of 100dp. Once the image view had set properly, I need to add list view also below the imageview.
My answer in comment : Add the ImageView in app_bar_main layout.
Reason why your code didn't work :
As per DrawerLayout specification
DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.
To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity because the XML order implies z-ordering and the drawer must be on top of the content . Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
Note the statement position your primary content view as the first child. In your case you want to place an ImageView below the Toolbar which means you want to modify the primary content. And the primary content is located inside app_bar_main layout.
But the image covers the toolbar and fit the entire screen, even I had given fixed height of 100dp
It is because Drawers commonly use match_parent for height with a fixed width.
Also remove the RelativeLayout from the main layout as it is useless. Make the DrawerLayout as the root layout.
References :
https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
https://developer.android.com/training/implementing-navigation/nav-drawer.html
Give an id to the app bar include:
android:id="#+id/mToolbar"
And add this in your ImageView:
android:layout_below="#id/mToolbar"
Since you're using RelativeLayout, you can use the layout below, above and other attributes to position your views.
Hint: Avoid hardcoding your values. Use match_parent or wrap_content or use your dimens.xml file to declare your values.
Actually RelativeLayout have feature to arrange its child below/above/left/right/center/top/bottom one layout to other using below property
BELOW
ABOVE
LEFT_OF
RIGHT_OF
CENTER_IN_PARENT
ALIGN_PARENT_TOP
ALIGN_PARENT_BOTTOM
I am creating an application in which i would like to know whether is it possible to show the list view inside a bottom sheet view .If so can anyone can tell me how i can do it because the examples which i have seen in bottom sheet shows only the share options.
Can anyone tell me is there any example relating this bottom sheets
Yes, You can implement Listview inside Bottom sheet View .
first you need to create xml layout for Bottom sheet, and defined Listview.
bottom_sheet_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center|top"
app:layout_behavior="#string/bottom_sheet_behavior"
>
<ListView
android:id="#+id/bottom_sheet_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</LinearLayout>
Defined BottomSheetDialog in your Activity.
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(TagSetupActivity.this);
View bottomSheetView = getLayoutInflater().inflate(R.layout.bootom_sheet_layout, null);
bottomSheetDialog.setContentView(bottomSheetViewVideo);
bottomSheetDialog.show();
ListView sheetListView= (ListView) bottomSheetView.findViewById(R.id.bottom_sheet_listview);
**and setadapter with data**
//**dataList == data fecth from sqlite.**
adapter=new BottomSheetListAdapter(this,dataList);
sheetListView.setAdapter(adapter);
Now, create BaseAdapter for showing data into List name with BottomSheetListAdapter
You can get an idea how to create a custom bottomsheet like a listview using below link
http://www.truiton.com/2016/07/android-bottom-sheet-example/
I would like to display on the bottom of the view frame layout which has some layouts inside of the FrameLayout hidden and are displayed after some button click. I would like to display the FrameLayout to start from bottom of the screen above all other views.
How can i do it in the right way please?
Many thanks for any advice.
I have implemented something similar to what you would like to achieve...first of all you should place your entire Activity of Fragment layout inside a CoordinatorLayout. Then you should place the FrameLayout which you want to show above all other views as the last View inside the CoordinatorLayout. You could give the FrameLayout a fixed height(200px) and the same negative value as margin bottom(-200px) so it can not be visible in the first place. And after some button click you can animate your desired view (in this case FrameLayout) to overlap all other views starting from the bottom of the screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//Your views here
<FrameLayout //Your FrameLayout
android:layout_width="match_parent"
android:layout_height="200px" android:layout_marginBottom="-200px">
//Place whatever views you prefer here
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Since Android Support Library 23.2 you can use Materials Bottom Sheets like the Google Map one:
Include the support design library (use the most recent version):
compile 'com.android.support:design:24.1.1'
You are supposed to use a component which is aware of nested scrolling like NestedScrollView (which extends FrameLayout by the way) and RecyclerView inside a CoordinatorLayout and add this behavior to it:
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
And to make it visible on the bottom just a little:
app:behavior_peekHeight="64dp"
What is the simplest way to attach a layout defined in xml at the top of Android soft keyboard.
This view should only appear when the keyboard appears.
I think the best way is to detect when the keyboard appears and then attach view to the bottom of the screen (it will be above the keyboard after resizing all layout).
I think the cleaner way to do this.
Define a layout resource file to use as your custom view
Create a method which inflates this layout resource file and return it as a view:
Code Snippet
public View returnPayKeyView(){
View simpleView = getLayoutInflater().inflate(R.layout.simpleresource,null);
return simpleView;
}
Set this returned view as the candidates using the setCandidatesView Method
The returned view will show above your keyboard, using the inflated xml layout resource.
One approach is to wrap your usual view layout in a FrameLayout and put the bit you want above the keyboard inside the frame along with your other view layout with a layout gravity of bottom.
My layout was along these lines:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- all your stuff... -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/stuffAboveKeyboardLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:background="#DDD">
<!-- stuff above keyboard... -->
</LinearLayout>
</FrameLayout>
The downside is that it will show even when the keyboard is hidden - but it ought to be possible to show / hide the view when the keyboard shows / hides: How do I Detect if Software Keyboard is Visible on Android Device?