I would like to know if this kind of layout is supported under Android and what is its name.
The description:
the application is revealed by default in a main view and a menu will appear when making a "swipe gesture" from the margins to the center of the screen; usually this layout has to offer some kind of callback or manage to stop the underlaying activity for the application so the user can use the menu without interfering with what he is doing with the application itself.
Thanks.
If you are looking for a sliding layout, here is an example:
you can call it with:
<com.slidingmenu.lib.SlidingMenu
xmlns:sliding="http://schemas.android.com/apk/res-auto"
android:id="#+id/slidingmenulayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
sliding:viewAbove="#layout/YOUR_ABOVE_VIEW"
sliding:viewBehind="#layout/YOUR_BEHIND_BEHIND"
sliding:touchModeAbove="margin|fullscreen"
sliding:touchModeBehind="margin|fullscreen"
sliding:behindOffset="#dimen/YOUR_OFFSET"
sliding:behindWidth="#dimen/YOUR_WIDTH"
sliding:behindScrollScale="#dimen/YOUR_SCALE"
sliding:shadowDrawable="#drawable/YOUR_SHADOW"
sliding:shadowWidth="#dimen/YOUR_SHADOW_WIDTH" />
There is no built in function like that, so you have to use third party libraries
There is no built in functionality for this behavior. You'll need to make it yourself.
Related
When I developed, I found a new widget called android.support.v7.widget.ButtonBarLayout unexpectedly. I tried to search it on the internet, but nothing was found, even on the official development documents site.
In the meantime, I found two ButtonBarLayout when I search ButtonBarLayout everywhere in Android Studio, one is android.support.v7.widget.ButtonBarLayout and the other is com.android.internal.widget.ButtonBarLayout. I tried to read source codes of both, I found that they are the same except package name. So I thought maybe android.support.v7.widget.ButtonBarLayout came from com.android.internal.widget.ButtonBarLayout after the internal ButtonBarLayout was through tests and released. At the same time, ButtonBarLayout is inherited from LinearLayout.
But there are some question:
What can we get from ButtonBarLayout literally and how should we use it?
I noticed the variable of private boolean mAllowStacking. When it changes, orientation of this layout would be changed. But I didn't really understand what it is used for.
So does somebody know ButtonBarLayout well?
P.S.: I used Android Studio of 2.0.0 Preview 4 and Gradle Plugin of 2.0.0-alpha3 and Android Support Library of 23.1.1 and Platform-tools of 23.1 and Build-tools of 23.0.2.
As others pointed out, the class description tells exactly what it is: an extension of LinearLayout that automatically switches to vertical orientation when it can't fit its child views horizontally.
I might add that this was clearly done to fit with the material design specifications about dialogs. They make a distinction between side by side buttons and stacked buttons. See for example:
Side-by-side buttons are recommended when the text of each label does
not exceed the maximum button width, such as the commonly used
OK/Cancel buttons.
While you should go for stacked buttons when the single button is too large, or there's not enough room for both:
When text labels exceed the maximum button width, use stacked buttons
to accommodate the text. Affirmative actions are stacked above
dismissive actions.
So, one possible use of this class, is when designing your own dialogs. For example, AlertDialog and AlertDialog.Builder offer internal support for dialogs with buttons, but sometimes you just want to subclass DialogFragment or AppCompatDialogFragment for a better control.
There, it might be useful to setup a bottom button bar that follows the design guidelines, and have full control on the buttons (like enabling and disabling, things you can't do with an AlertDialog AFAIK).
The source code describes ButtonBarLayout as follows:
/**
* An extension of LinearLayout that automatically switches to vertical
* orientation when it can't fit its child views horizontally.
*/
So, in essence, it is nothing but a smart LinearLayout which manages auto-switching orientations based on available space on screen.
The same ButtonBarLayout.java file describes mAllowStacking in comments as follows:
/** Whether the current configuration allows stacking. */
Source Code Here
You are right first of all. ButtonBar layout does not seem to be featured anywhere in the official Android documentation. I tried myself to search about it, but to no avail. However I have found some information which defines what is a ButtonBar layout and when to use it. Hopefully this will help you.
Most tutorials use the Buttonbar layout in a dialogbox or at the bottom of a screen to confirm or decline an option. The image below is a visual representation of how the ButtonBar layout has been used in a screen.
The screenshot above has the following layout xml:
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/Button01"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Show" />
<Button
android:id="#+id/Button02"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Change" />
</LinearLayout>
<EditText
android:id="#+id/myView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
So essentially what Android is doing here is simply creating two buttons next to each other in a LinearLayout with each button having the match_parent parameter set to the width. Hence each button takes half the size of the screen. Android have actually taken away the hassle of creating seperate buttons and positioning them correctly to fit different screens, by creating a simple widget handling this altogether.
As with the support library, Android have implemented this for developers using an earlier API. It is normal for them to use the support library for this purpose.
Hope this helps :)
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/com/android/internal/widget/ButtonBarLayout.java
Looking into the code, I think it's a LinearLayout for buttons (duh). You can probably look at it like the Dialog buttons divided by a vertical spacer: | . AllowStacking will change the orientation to vertical and the gravity to the right instead of bottom. I should try it out to give a better answer
ButtonBarlayout is not featured anywhere in the official Android documentation.
it is used for auto-switching orientations according to the space.
Regarding your question:
How should we use it?
I guess it is undocumented because it is not stable yet.
It just popped up because this long lasting complaint originate from poor ROM modification by device vendor.
https://code.google.com/p/android/issues/detail?id=78377
See #270 for the resolution regarding classpath and why all classes inside .internal. were made public.
And nope even that fix a lot of bugs from poor ROM modification are still out there (in lots of device of well known brands). The issue is soon declined by project member.
I don't think we should use it just yet until the document show up.
Just my $.02 though.
Just to add to the other answers, if you guys want to check the orientation of a ButtonBarLayout you should check the orienation AFTER the value has called on measure.
In other words (Kotlin):
buttonBarLayout.post {
val orientation = buttonBarLayout.orientation
val height = buttonBarLayout.measuredHeight
}
Is it possible to show a preview layout for ViewPager in AndroidStudio like in ListView/RecyclerView/etc.?
Short answer: No.
I think you're talking about ViewPager from ViewPager 2. My answer will be assuming ViewPager 2. Pls update the question to clarify that.
- Workaround: a hidden include
<include
android:visibility="gone"
tools:visibility="visible"
layout="#layout/item_that_shows_inside_viewholder"/>
And I agree that's a very poor way to do it.
If in constraint layout you can loosely match the same constraints to make this show on top. And yes, you will inflate this in production code so you may incurr in performance slow down depending on what you have there.
It's very unfortunate that tools:layout doesn't exist or work properly (yes, I got inconsistent results while trying it).
- 2nd less worst way is using isInEditMode on code on the parent class
something in the fashion of
class CustomView ....
init {
// inflate layout that contains ViewPager
if ( isInEditMode() ) {
//do something that replaces ViewPager with its inflated view holder
}
}
which has served me well when I can use that. However that's unsuitable for most places.
- If at least ViewPager were not final we could extend and do some tricks there using isInEditMode like above.
- You can make a custom class wrapper with internal field ViewPager
One way that does certainly work is making your custom class extend FrameLayout and having an internal view that is your actual ViewPager. But then you have to re-implement and delegate all its methods, which is a big pain. Maybe kotlin has a way to do that, but so far I don't know how. Or maybe using reflection or kotlin poet could be a way to do that. It's too risky for my taste.
- If we could make a databinding adapter to do the isInEditMode like above it would work. But databinding adapters don't run in preview.
- I tend to think these tools attributes get processed by Android Studio, so it would take probably an android studio plugin to work around it.
This is the current full list of tools attributes: https://developer.android.com/studio/write/tool-attributes.html#toolslistitem_toolslistheader_toolslistfooter
It may be useful reading this Android XML Is there a way to use the tool namespace with custom attributes?
where a library to read custom attributes with tools gets mentioned. There may be an alternative with this library, but I have never used it and not sure how it works:
https://github.com/giljulio/sneakpeek
I'd love to be proved wrong, but in my opinion all of the options are dead ends or too much effort.
In Andriod studio some views are shown in run time but not in compile time. Think about Frame Layout as a container for fragment transaction. We may place any kind of views on that container in run time. So, it's not possible to show a view while coding. The viewpager is playing same kind of role here. So, we can't show a view there before running and actually placing a fragment/other view there.
I hope you are clear now. :)
This is possible, when putting the ViewPager into it's own XML layout resource.
Alike this one can show the desired Fragment instead of the ViewPager:
<fragment
android:id="#+id/fragment_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="#layout/fragment_viewpager"
tools:layout="#layout/fragment_preview" />
This also provides the XML preview for the navigation graph design view.
tools:layout only works with fragment, but not with include.
i think it's not...some of the layouts have no preview while coding or designing ...like TabLayout
Although I don't think there is such a functionality out of the box, I used the following workaround to achieve design time preview for the ViewPager:
Add an <include> with the view that you will use in your ViewPager as a layout,just after the ViewPager itself
Set tools:visibility="visible" and android:visibility="gone" to this <include> view so that it will be visible at design time but not at runtime. Also set tools:visibility="gone" to the ViewPager so that it will be invisible at design time.
The idea is to hide ViewPager at design time and show its contents instead while doing the opposite at runtime. This should work for other controls as well.
To show an example:
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/tabl1"
tools:visibility="gone">
</androidx.viewpager.widget.ViewPager>
<include
layout="#layout/fragment_example1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintTop_toBottomOf="#id/tabl1" />
I hope this helps you
I have implemented a SlidingPaneLayout with fragments that looks like this (summarizing)
<SlidingPaneLayout
android:xmlns="...."
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ListView />
<FrameLayout />
</SlidingPaneLayout>
So the ListView is the "slide out" pane. It all works fine and exactly as I expect it to.
However, I'm interested in achieving the animate affect (where the ListView would come in from the left as the pane is pulled out, following the touch)
I've tried making a slide_in_left anim resource and setting it as a LayoutTransition, however this doesn't behave like I want it to. Guessing I need to do something with onPaneSlide?
Just wondering if there's a good way to implement this with SlidingPaneLayout, thanks!
Wow it's too easy I just overlooked it big time.
SlidingPaneLayout has a method, setParallaxDistance, which adds the effect I was referring to.
http://developer.android.com/reference/android/support/v4/widget/SlidingPaneLayout.html#setParallaxDistance(int)
I am new to Android development and Eclipse. I have been coding on ASP.Net and MS Visual Web Developer for years. In VWD, when you add a control to the design view, double clicking on it will automatically bring you to code view for the OnClick function of the control you have just created. You can also see the list of possible event handlers for a control from the design view.
But I can't seem to find this feature in Eclipse. Is there such a thing? I did a search on Google and the best I found is this (same question but without an answer).
http://www.techrepublic.com/forum/questions/101-341077/event-handlers-in-eclipse
Anyone to advice please?
Thanks!
What you're talking doesn't quite exist in Eclipse. You'll have to manually open your java class and add the method to the corresponding java activity there.
For example, if you set the android:onClick XML attribute to "myAwesomeMethod" in your layout XML file, in the corresponding Activity that uses that layout, you'll need to make sure you have a "myAwesomeMethod" method defined.
<?xml version="1.0" encoding="utf-8"?>
<!-- layout elements -->
<Button android:id="#+id/mybutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me!"
android:onClick="myAwesomeMethod" />
<!-- even more layout elements -->
In your java Activity class:
public void myAwesomeMethod(View v) {
// does something very awesome
}
Note: you can also do this programmatically, which is what I generally do. However, defining the android:onClick method will save you a few lines of code.
For more information, check out this post. It gives a lot more detail on how to assign onClick handlers to a button and the two ways you can do so.
No, that is not how Eclipse works. You add the control in the xml file, then in the activity that you are going to load that layout in you add the onClickListener on the element you want to respond to clicks for,
For clarification: I want all the custom dialogs to look like system default dialogs: for example, when user is using htc sense, the dialog should match htc sense dialog style, when user is using samsung with official customasation, the dialog should look like it. I want to go as native as possible. I am familiar that there are possibilities to modify the dialog, but I'm looking for a way to reference to the style the system uses and create a dialog with that.
What I have:
What I would like to achieve:
Code for my dialog layout which I invoke with dialog.setContentView(...):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#android:style/Theme.Dialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" >
</ListView>
</LinearLayout>
As you can see setting the style="#android:style/Theme.Dialog isn't helping. Any ideas what might be helping?
(I am familiar that there is already such a question: https://stackoverflow.com/questions/6746535/android-custom-dialog-but-with-look-and-feel-of-default-one but there isn't an accepted answer)
If you want the dialog that appear just for your application purpose then follow this:
See this image i have create this one to save Image or Post it to different way.
I have created the xml layout as per my requirement. If you want to add the list view as you have explained in to the question then you have to manualy implement that behaviour in the content of the dialog. Means for such layour You have to implement the Custom ListView that have that radio button and text. And also have some Java code to do action according to that selection.
With that you can acheive as you want.
Enjoy. :)
You can build a native-look like dialog for one UI, but when another user has some other ROM/modified UI, then the dialog doesn't look like a native one to hem/her. There isn't a built in functionality, to access system dialog resources and populate all dialogs from native layouts only.