Android Studio - Relative Layout on top of buttons have transparent background - android

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);

Related

How do I fix a layout at bottom and at top without hiding elements on Android?

I'm having problems when using RelativeLayout, ScrollView and some LinearLayout to get some elements always on top and something scrollable.
This is my XML
https://pastebin.com/Uai2UynP
(I don't know why it got separated in this post but it's the same code)
The point is, when i add the android:alignParentBottom="true" to the RelativeLayout with the "always on top bar", it hides me a part of the ScrollView above. This can be solved adding a android:PaddingBottom="[something]" to the ScrollView above, but doing this it hides me something at the top, since I basically have the LinearLayout with email, gold and coin that i want too always on top.
Use RelativeLayout as main layout and use android:layout_alignParentTop="true" in your layout which you want to place top and use android:layout_alignParentBottom="true" in your next layour which you want to set bottom of your layout. I am giving you a Example,
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
</RelativeLayout>
</RelativeLayout>

Android XML: Drop shadow cut off

I have a relative layout with a margin and a floating action button that is nested inside this 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/activityMargin"
android:orientation="vertical"
android:clipToPadding="false">
<android.support.design.widget.FloatingActionButton
android:id="#+id/id_FABSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
app:srcCompat="#drawable/ic_save_white"/>
</RelativeLayout>
As you can see in the attached picture, the drop shadow of the floating action button is cut off. How does this happen and how can it be fixed?
In your relative layout tag, use padding instead of margin and add the attribute android:clipToPadding="false" to avoid the shadows being cut.
<RelativeLayout 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:padding="#dimen/activityMargin"
android:clipToPadding="false">
Problem is that shadows are cut by bounds of view or view group. To tackle this issue you have to use:
android:clipChildren
Defines whether a child is limited to draw inside of its bounds or not.
android:clipToPadding
Defines whether the ViewGroup will clip its children and resize (but not clip) any EdgeEffect to its padding, if padding is not zero.
Problem is that you have to set this to many views in xml if you want to render shadow. I resolved this issue on level of themes.xml. In my top level theme I just set:
<item name="android:clipChildren">false</item>
<item name="android:clipToPadding">false</item>
Then, if there is space on screen, shadow is rendered. I hope it won't break something else.
EDIT: It breaks some views. For example CameraPreview will set black background to whole screen. Be careful with scrolling views, etc.

Android half screen activity

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.

Relative Layout with a nested Linear Layout inside. How to position the Linear layout at the bottom of the screen?

I have a Relative Layout which has a Photo Gallery and a Media player in it. My problem is I want the media player controls (pause/play/forward/rewind) 4 buttons to be positioned at the bottom of the screen while maintaining its center horizontal alignment. What I did was
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="#+id/main_audio_view"
android:layout_height="match_parent"
android:background="#drawable/backgroundimg"
tools:context="com.my.project.LaunchGalleryview">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_centerInParent="true"
android:gravity="bottom"
>
</LinearLayout>
</RelativeLayout>
The cuttons inside the Linear Layout are allinged center but the whole Linear Layout is positioned at the center of my screen. I want it to be at the bottom of the screen. I already tried andoird:gravity="bottom" it still positioned center of the screen how can I force it to be at the bottom?
Instead of
android:layout_centerInParent="true"
Use
android:layout_alignParentBottom="true" <!-- Bottom of the RelativeLayout -->
android:gravity="center" <!-- centers all child views within the LinearLayout -->
Just add android:layout_alignParentBottom="true" to the LinearLayout
Try this in the Linear layout
android:layout_alignParentBottom="true"

How to add two buttons in a bar in linear view in Android?

I have two buttons in a linear view and I want to add them to a bar.
How can I create a bar that appears at the bottom with the buttons in it?
You can use a relativelayout to make a bar appear bottom always like
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true">
<!-- Here you put your buttons -->
</LinearLayout>
</RelativeLayout>
You also can use
a FrameLayout: http://xjaphx.wordpress.com/2011/06/25/create-floating-view-using-framelayout/
a RelativeLayout: http://xjaphx.wordpress.com/2011/06/25/ui-design-keep-the-bar-floating/

Categories

Resources