I want to create activity with one button. When you click on the button, half screen layout appears from bottom.
And more when you click on background layout, new front background disappear.
Do you have an idea who to implement this?
Thanks in advance.
EDIT:
I have found solution for this feature.
Firstly, I make new hidden view below the screen( You can found how from the answers below).
And then, I animate on button click with the following code:
dialog.animate().translationY(-HEIGHT).setDuration(TIME);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- view with button -->
<LinearLayout
android:id="#+id/task_list_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>
<!-- example content hided in bottom -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/height_of_your_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/minus_height_of_your_content"
>
</LinearLayout>
</RelativeLayout>
To show hide content change it marginBottom. In start marginBotton should be - of this layout height to be out of screen. You can do it using animation on translateY and on end change marginBottom to finish value. This is one of possible solutions.
Related
I am implementing a approach where there is fragment and it contains the initial layout with some data. Now I want to shift that initial layout down if there is notification pops up and up if notification is gone. I am wondering how can I implement that ? How can I shift up and down the layout based on notification is available or not ?
Here is a design.
layout
Image-A is the initial layout with no notification and Image-B is the layout after additional layout(notification) at top.
Thanks
Just have the notification always in the layout, but set its visibility to GONE when it shouldn't show. That tells the layout to not show it and not take up any space for it. Then when you want to show it, set it to VISIBLE.
What you want to implement is called Banners and you can implement it using Motion layout, Here's more detail about them on material components
Follow this tutorial, you can implement it very easily.
You can use animateLayoutChanges as true on your root layout (considering that notification and body layout are in the same file)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/notificationLayout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="12dp"
android:background="#color/orange_300"
android:orientation="vertical">
<!-- body here -->
</LinearLayout>
<LinearLayout
android:id="#+id/mainBody"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
android:background="#color/blue_300"
android:orientation="vertical" />
</LinearLayout>
When you change notificationLayout visibility (VISIBLE OR GONE), you will get the animation you want.
I want to make a view( a button actually) which is inside a scrollview , but when the user scolls down and the button is going up, it moves up only till it reaches the top of the visible screen and then stays there like a fixed header until the user scrolls up again and then it returns to its original position.
I have given the screens for understanding ;
At Start
Then
Change you parent viewgroup to RelativeLayout and then make a Button and ScrollBar as a direct child of this RelatieveLayout.
You can simply achive this by
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
------put your code here-----/>
<Button
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
I am trying to create a RelativeLayout on the top of another containing buttons in order to hide the ones below.
I have set a black background to the top RelativeLayout however, the layout is till transparent showing the objects underneath. Also The buttons behind the top relative layout are still clickable.
My question is how can I use a RelativeLayout in order to hide another one containing object underneath? The top relative layout should be NOT transparent and the buttons underneath not clickable.
<?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"
android:orientation="vertical">
<RelativeLayout
android:visibility="gone"
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your buttons go here -->
</RelativeLayout>
<RelativeLayout
android:id="#+id/prompt"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- your prompt -->
</RelativeLayout>
</FrameLayout>
and when you're done with your prompt relative layout, then from your activity say something like this:
View prompt = findeViewById(R.id.prompt);
prompt.setVisibility(View.GONE);
and then visible your button layout
View buttonLayout = findeViewById(R.id.buttons);
buttonLayout.setVisibility(View.VISIBLE);
I have a top bar with a show/hide menu button. I would like to define the top bar, the button and the menu in the same layout.
I tried a layout with the height of the top bar, but the menu is clipped and is not visible. Is that possible to have a view larger than its parent. Otherwise, what's the standard way to do that?
For your question: Yes It's possible. Simple example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f"
android:layout_marginLeft="-50dp"
android:layout_marginRight="-50dp"
/>
</LinearLayout>
And ImageViewWidth == LinearLayoutWidth + 100dp.
Hope its help.
i am designing an application which have diff types of functionalies through buttons/image buttons. At final the list might increase. i want to put one custom home button which always keeps on screen when i am in diff activities.
or either if you have any idea about how this Home button is coded to this layout
below screen. please help.
Have you considered the Action Bar which is exactly designed for this purpose?
http://developer.android.com/guide/topics/ui/actionbar.html
While the home button at the bottom can be easily achieved using an image view/button,Using an action Bar is the recommended option.Not only can you link with the home activity but also any other activity of your choice.Refer this to gain a deeper insight.
http://developer.android.com/guide/topics/ui/actionbar.html
http://developer.android.com/reference/android/app/ActionBar.html
You can either place a button/image button/image anything in xml layout and set on click listener on that component. You can also use option menu and give multiple option on all the screens of your application.
Make a layout with a ScrollView on top, and your image-button below the scrollview.
Example:
<!-- language: lang-xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your Content Here"
/>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
</LinearLayout>
It looks like this: