android:How to move a RelativeLayout permanently after animation - java

This is the activity.xml and content_my.xml is a RelativeLayout and menu.xml is LinearLayout. Content layout(RelativeLayout)in the top and menu layout(LinearLayout) under the I want to move the Relative layout(content layout) left of screen and access the menu layout under it. content layout is in the top of menu layout after animation it menu cannot be accessed. In contentlayout I have add ListView. Please help me how to move the RelativeLayout left permanently after animation.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.bwd.demo.mybrand.My">
<include layout="#layout/menu" />
<include layout="#layout/content_my" />
</android.support.design.widget.CoordinatorLayout>

In your content_my.xml you have to assign an ID to your RelativeLayout :
android:id="#+id/rl_content"
Then you cast the xml in Java code in your Activity so you can use it :
RelativeLayout rl_content = (RelativeLayout) findViewById(R.id.rl_content);
Now there are multiple options to animate it.
Since you want to access something below the layout, I would recommend
using ViewPropertyAnimator, then you can do it with one line.
A minimal implementation would look like this :
rl_content.animate().translationX(0); // -> animates **TO** 0 on the X axis
would move the left border of the layout to the left side of the screen. If you want it further then you need a negative value.
or you can use the translationXBy() method f.e. :
rl_content.animate().translationXBy(-50); // -> animates **BY** -50 on the X axis
//(negative values are to the left)
Also interesting :
TranslateAnimation -> not recommended in your case, because it does not really move the layout, only makes it look like its moving, so you would have trouble accessing the menu under the RelativeLayout.
ObjectAnimator

Related

How to define custom margins to StepperLayout navigation buttons

I have a StepperLayout that displays a list of questions to the users. However, half of the "NEXT" navigation button is hidden after giving it a background color. I want to define custom margins and alignments to the navigation buttons. See the gif image below.
I have tried overriding the codes used for the NEXT and BACK button but that displays duplicate buttons. I have also tried adding some paddings to the StepperLayout but still, it didn't help.
<com.stepstone.stepper.StepperLayout 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/stepper"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ms_activeStepColor="#color/stepper_btn_blue"
app:ms_nextButtonBackground="#color/stepper_btn_blue"
app:ms_backButtonColor="#000000"
app:ms_completeButtonColor="#color/colorWhite"
app:ms_completeButtonText="Finish"
app:ms_stepperType="tabs"
tools:theme="#style/AppTheme" />

Tips horizontal scroll with textbox

I would like to make horizontal swipe scroll with images and text views on it, 3-4 views.
Like tips screen on applications.
But, don't know which component to use, I need something like tabs(3-4 different layouts) but I dont want to show tab menu up. Just full screen, few buttons down, and in middle textbox with tip(which i want to animate later), everything is same in every layout just different image and text.
No code here in question because i stuck on beginning and need few tips what to use or some linked tutorial.
Here is how you can do this.
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pro_flip"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//put your child elements for first page on this layout
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//put your child elements for second page on this layout
</LinearLayout>>
</ViewFlipper>
Content on the first layout will be visible to the user at first, when he swipes the next layout will be loaded.
ViewFlipper should be sufficient for simple content like you mentioned. If you want something more look into ViewPager.

Fragment: overwrite activities margin

I have an Activity container for several different fragments. All fragments should have the same margin except one. This should has no margin. But how can I do that?
This is my activity_container.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp" />
All fragments within this container have a margin of 15dp. But there is one fragment, that should have 0 dp. The fragment have to be in the container. So creating a container only for this fragment is no option. Do somebody has an idea to solve that problem?
The fragments cannot be displayed outside of their container, just as with any other view.
Your only option is to remove the margin from your relative layout and add it back as padding onto the individual fragment layouts

Android – How can I Move a Layout Partially Offscreen?

I am trying to make a sliding menu in an android application I am building for my school, and whenever I open the menu, the menu button, in addition to the other views I've tried, are scaled to fit in the remaining 25% of the layout still on the screen. So my question is, how can I disable this scaling so views can be moved offscreen along with their parent layout?
This is the XML file of the layout I am trying to move. It contains the misbehaving button:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/background_color"/>
<ImageButton
android:id="#+id/menu_button"
android:layout_width="56dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:background="#drawable/menu_button"/>
</RelativeLayout>
This is what the menu looks like closed:
This is how it looks when opened:
And this is how I want it to be when opened. Notice the menu button has moved offscreen.
Any help is appreciated.
EDIT:
Although it may work for a single button, I do not want to make the views invisible, I would like to move them off the screen to the right. If, for example, I wanted to add a TextView that fills a horizontal row on the layout, the TextView would be scaled to 25% of the screen upon opening the menu. Instead, I want it to retain the size and shape of all views and make them move partially off screen.
When menu opens up, set the visibility of menu icon to GONE
icon.setVisibilty(View.GONE);
and when close , again set visibility of icon to VISIBLE.
icon.setVisibilty(View.VISIBLE);

How to create fixed layout in Android

My activity has spinners, which supposedly should be in the centre. Relative to the spinners positions, buttons and labels are placed.
Another activity has 8 buttons in which certain values will be displayed. I have used a RelativeLayout in all activities. My app works well on my Moto G, but on bigger devices, the alignment of all the buttons and spinners changes.
I want to fix that issue.
Use this in the case of RelativeLayout
android:layout_centerInParent="true"
This will make the element always stick to the center of the device irrespective of the size of the device. Try it..
eg:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton android:id="#+id/btnSample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"></ImageButton>
</RelativeLayout>

Categories

Resources