Menu
  • HOME
  • TAGS

Android ViewFlipper with translation animation - not working properly

Tag: android-layout,android-animation,translation,viewflipper

I want to display banner(images moving in x direction) in my application. For that i am using ViewFlipper with Translation animation. Please find my below code..

my layout: banner.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
        <ViewFlipper
                android:id="@+id/banner_image"
                android:layout_width="match_parent"
                android:layout_height="258dp" />
</RelativeLayout>

In animation: in_from_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

  <translate
    android:duration="3000"
    android:fromXDelta="100%"
    android:fromYDelta="0%"
    android:toXDelta="0%"
    android:toYDelta="0%" />

</set>

Out Animation: out_to_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
  <translate android:fromXDelta="0%" android:toXDelta="-100%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="3000"/>
</set>

My Java Code

public class BannerView extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.banner);

    ViewFlipper myViewFlipper = (ViewFlipper) findViewById(R.id.banner_image);

    //Setting first image in viewFlipper
    ImageView imageView1 = new ImageView(HomeView.this);
    imageView1.setImageDrawable(getResources().getDrawable(R.drawable.img1));
    myViewFlipper.addView(imageView1);

    //Setting second image in viewFlipper
    ImageView imageView2 = new ImageView(HomeView.this);
    imageView2.setImageDrawable(getResources().getDrawable(R.drawable.img2));
    myViewFlipper.addView(imageView2);
    myViewFlipper.setAutoStart(true);

    //Setting in and out animation
    myViewFlipper.setInAnimation(HomeView.this,R.anim.in_from_right);
    myViewFlipper.setOutAnimation(HomeView.this,R.anim.out_to_left);

    //Starting the view filpper to rotate
    myViewFlipper.startFlipping();
}
}

Here my problem is,

When i set the duration for in and out animation as "5000", ViewFilpper's behavior is changing like the below,

Image start to move slowly and ending quickly.

I dont know where i am missing. I want to slow down the speed. Please help me resolve the issue.

Best How To :

Thanks for your reply. I found the solution for my problem. Please find my answer below.

I have changed my interpolator in xml as below:

 android:interpolator="@android:anim/decelerate_interpolator"

And then i used android:flipInterval="5000" in my viewflipper solved my problem.

How to add a text with image with exactly half in the layout in android?

android,android-layout

You need to use weights in a LinearLayour in order to equally size Views. For this to work, you will have to ensure that you add android:layout_width="0dp" (or layout_height if the LinearLayout is set to a vertical orientation) in order for the weight to take precedence. For example: <LinearLayout android:layout_width="match_parent"...

How do I make a textview fill the height of a linear layout?

android,android-layout,textview

The solution is to use android:fillViewport="true" on the ScrollView and change this LinearLayout android:id="@+id/note_view" child control height from wrap_content to fill_parent....

how to pass data intent in different textview in android

android,android-layout,android-intent

I don't understand fully what's the purpose of your code, or the semantics of the variables, but I believe you want to set the default value to 0 on your getIntExtras Integer hasilNormal1 = hasilIntent.getIntExtra("hasilBNormal1", 0); Integer hasilNormal2 = hasilIntent.getIntExtra("hasilBNormal2", 0); ... Also, it seems that you are losing the...

android.view.InflateException: Binary XML file line #13: Error inflating class

android,xml,android-layout

Try to remove app:font="@string/lusitana line. and try How to change fontFamily of TextView in Android to change font style.

Inflating ImageButton programatically changes width & height params to wrap_content. Why?

android,android-layout,android-inflate,layoutparams

When you call inflater.inflate(R.layout.child_button, null, false), you are passing in null for the parent view - this causes any layout_ attributes to be ignored (as those attributes are only used by the parent view) - see this Google+ post for more details. Instead, you should use inflater.inflate(R.layout.child_button, right_LL, true)); This...

Change background on FloatingActionButton?

android,android-layout,material-design

Ok I figured it out. Turns out you do have to set the background to a drawable (thanks @Nilesh), but there was something wrong with the drawable I was setting it to. I used this: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="oval"> <solid android:color="@color/al_color_accent_orange_light"/> </shape> </item> </layer-list> as my...

Bottom 96 Pixels of Nexus 4 Screen Missing - Get Window Dimensions for Nexus 4

android,android-layout,nexus-4

The display of the Nexus 4 is 1280 x 768, however the Android system buttons take up part of the screen. Your height returns 1184 as this is the full height of the display (1280 pixels) minus the 96 pixels taken up by the Android system buttons....

None linear activity transition animation

android,android-activity,android-animation,android-transitions

android:interpolator let's you manipulate the rate of change of an animation. If you want to starts out slowly and then accelerate use AccelerateInterpolator. <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="@android:integer/config_mediumAnimTime" /> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator"...

Set portrait only orientation on devices with a screen size of less than 7 inches

java,android,android-layout,android-activity,android-orientation

Store some Boolean in values folders. There can be multiple values folders like values-h720dp or values-w320dp. Then read those data in oncreated method of activity and then set proper orientation. To learn more read this

Difference between preference fragment and “regular” fragment

android,android-layout,android-fragments,robolectric

Preference fragments are very different from regular fragment. Their layout is defined by the system and the content is inflated from XML resources. The purpose of this is to provide consistent settings screens in your apps. Have a look at the API Guide for more info.

ViewPager not showing page content / not refreshing after changing the view

android,android-layout,android-fragments,android-viewpager

If you want your fragments to maintain its state even after changing the tabs, Try this, mViewPager.setOffscreenPageLimit(5); //as you have 5 fragments But this will make the activity to initialize all the fragments at the same time when the activity is invoked. Another method is to use FragmentStatePagerAdapter instead...

Can't Open Fragment when clicked button

java,android,xml,android-layout,android-fragments

Try this I guess it will work for you <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${packageName}.${activityClass}" android:id="@+id/semester"> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/fragmentLayout" android:layout_centerVertical="true"...

Custom editText on android

android,android-layout,android-edittext,frontend,android-custom-view

If you want the blue line on the left, you can just set the background on the EditText, such as, <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/custom_edittext" android:layout_weight="1" /> Then create another file in your drawable folder this is called custom_layer.xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="-5dp" android:right="-5dp"...

How to add Ripple effect in RecyclerView

android,android-animation,android-recyclerview

Here's a good library: RippleView Hope it helps. Update The library above is only for Buttons, as I was pointed out. This library, RippleEffect, you can have the Ripple Effect to Views too....

OnClick on inflated items

android,android-layout,android-inflate

You can find those images and check if it's not null before setting onClick. ImageView img1 = (ImageView) view.findViewById(R.id.imageview1); if (img1 != null) { img1.setOnClickListener(...); } ImageView img2 = (ImageView) view.findViewById(R.id.imageview2); if (img2 != null) { img1.setOnClickListener(...); } ... ...

Circular Reveal Android Soften Edges

android-animation,android-5.0-lollipop,android-transitions,circularreveal

No, there is no way to do that using the circular reveal animator. You'd have to make your own to soften the edges, but the performance is likely to be horrible. The typical circular reveal is very fast and it is difficult to see the hard edges....

Spinner height expands to bottom of screen

android,android-layout,android-fragments

Try modifying the following line in you .xml file android:dropDownWidth="match_parent" to android:dropDownWidth="300dp" or wrap_content Hope this should help !...

Animations are clipped to ViewGroup bounds in Android 4.3 and below?

android,animation,android-animation,viewgroup,android-viewgroup

I've just done some trial and error and found a solution to my own problem :) (Don't you just love it when this happens??) Basically where I was calling my invalidate() on my custom view in order to draw the animation, I need to also call ((View) getParent()).invalidate() in order...

How to inflate views programmatically in vertical order

java,android,android-layout

Use a listview is correct. Try doing this (A little bit more elaborate than what you have but worth it. Create a Task object that implements Pacelable. This object can be sent back in the result of AddTaskActivity public class Task implements Parcelable { private String myTask; private String myDetails;...

Create Same Size Image Across Various Android Densities

android,android-layout,image-manipulation,android-image

You have to add images of various dimensions in various drawable folder viz- drawable-ldpi,drawable-mdpi and so on. And the image dimension ratio will be: Taking mdpi as a base your ldpi will be 0.75 times of mdpi hdpi - 1.5 times of mdpi xhdpi - 2 times of mdpi xxhdpi...

Android: Fullscreen landscape Video with hideable Navigation Bar, but do not overlap the progress bar

android,android-layout

You can break this task up into 2 simple steps: 1) Determine the size of the Navigation Bar 2) Set the margin of the progressBar size of the Navigation Bar. 1) Determine the size of the Navigation Bar Method 1 Use android.R.dimen.navigation_bar_width. It's not accessible through the public API, but...

How would I make a grid layout occupy 1/2 of a screen?

android,android-layout

Try setting the weightSum attribute on the parent LinearLayout. In the following example, the weight of the GridLayout will be 1 out of a total 2 (so 1 half). <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="2"> <GridLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> </LinearLayout> ...

Android. Making my object appear anywhere on the screen

android,android-layout

The thing about gridview is that its entire purpose is scrolling. If you have lots of data and want to scroll through it in a grid, that's the right answer. If you have a fixed amount of data you want to display in a grid, you want something else- a...

Positioning Cardviews below eachother not working

android,xml,android-layout

Watch out when you copy - paste code. All your cards have the attribute android:layout_alignParentTop="true"...

Difference between match-parent and fill-parrent [duplicate]

android,android-layout

After API 8, FILL_PARENT was renamed as MATCH_PARENT. So , both are one and the same. Official doc : http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.htmlenter link description here...

Move textview from top to bottom

android,xml,android-layout,layout

Please use this <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/card_tracks" android:layout_width="match_parent" android:layout_height="180dp" android:layout_gravity="center" android:layout_margin="16dp" android:elevation="7dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/main_ll" android:layout_width="match_parent"...

Why can't ListView be top level view?

android,android-layout,listview

It can, as long as you don't expect to put anything else in the layout. FrameLayout, same as Linear and Relative, are containers for several views, but if you only have one you don't need them. Most layout files seen online assume you may want to expand on your ui...

ExpandableListView expanding over other layout

android,android-layout

I have made some changes in your XML File.What I did is make your Button Layout android:layout_alignParentBottom="true" and make your details layout as android:layout_above="@+id/button_layout".Hope it will solve your issue. <?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"> <LinearLayout android:id="@+id/details" android:layout_width="match_parent" android:layout_height="wrap_content"...

How to check weather the indirect child exists in View or not?

android,android-layout,view

As answer as requested in comment-section: I would not use by index because it couples code<>layout to tight - you just can findViewById on your parent: parentView.findViewById(vmax_tv_desc) ...

delay slide action when an image is clicked using viewpager android

android,android-viewpager,android-animation

Try this out. Add this code in your onClickSlideDown method. Thread timer = new Thread(){ public void run(){ try{ sleep(2000); }catch(InterruptedException e){ e.printStackTrace(); }finally { //Your entire code of onClickSlideDown method } } }; timer.start(); Hopefully this will work and delay the slide by 2000 miliseconds. UPDATE : If the...

Configure CoordinatorLayout from code

android,android-layout,android-coordinatorlayout

Taking one step back and building the entire view in plain xml, I realized that layout_below is not the property I needed for my use case: placing the content view below the app bar. I did not make this clear in my question though, as I assumed layout_below would be...

Ending multiselect in a listview removes list item padding

android-layout,android-listview,recyclerview,android-4.1-jelly-bean

Finally found the solution! The problem lays in the layout XML file: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_item_doc" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:padding="12dp"> The background attribute apparenly isn't valid for Jelly Bean devices. Changing the value from android:background="?android:attr/selectableItemBackground" to...

Setting Content in a EditText

java,android,xml,android-layout

Your method needs to have a View parameter, which will contain the button you clicked. So, your code could look like this: public void number(View v) { EditText result = (EditText) findViewById(R.id.result); // get the text from the button that was clicked and add it to the EditText result.setText(result.getText() +...

Why are these buttons mis-aligned in a TableLayout?

android,android-layout

Add the following attribute to your TableRow: android:baselineAligned="false" By default, the button labels' base lines are vertically aligned which causes the offset you experience....

Why elements adding at the end of ListView?

android,android-layout,android-listview,android-adapter

I think this is because of your layout file. Change the android:layout_height=wrap_content of your ListView tag to android:layout_height=match_parent.

The specified child already has a parent. You must call removeView() on the child's parent first”

java,android,android-layout

You could change this: linearLayout.removeAllViews(); to this: ((ViewGroup)Main_layout.getParent()).removeView(Main_Layout); The linearLayout doesn't have any views yet (you just created it), so the linearLayout.removeAllViews() call is redundant. What you need isn't to remove all views from the Main_Layout's new parent, but to remove the Main_Layout from its previous parent. What I would...

titanium tableview font color

android,android-layout,titanium,tableview

According to Titanium docs; TableView does not have color property. What you can do is create TableViewRow and add them to TableView; and finally applying TableViewRow's color property. Example below: var tableData = [], win = Ti.UI.createWindow(); tableData.push(Ti.UI.createTableViewRow({ title: 'Apples', color : "#000" })); tableData.push(Ti.UI.createTableViewRow({ title: 'Bananas', color : "#000"...

findViewById returns null when try to find TextView in getView [on hold]

android,android-layout,listview,android-adapter

you used viewGroup.findViewById(R.id.tvEmployeeNameSurname); but you should use like view.findViewById(R.id.tvEmployeeNameSurname);...

Error Parsing XML: not well formed (invalid token)

xml,android-layout,layout

</> is not a valid token in an XML file. The closing tag of the RelativeLayout should be </RelativeLayout>...

How to delete the complete view on click of delete button in android

android,android-layout,android-activity,android-listview,android-arrayadapter

I would recommend to use an ArrayList instead of a String[] in your Adapter class. It makes it a lot easier to delete or edit a View and the associated data behind it. I used this post to convert your String[] to an ArrayList, delete the item and convert back...

How do I add a button to an Android Frame Layout, in the same position as my picture (centered in the bottom 4th of the screen)?

android,android-layout,android-button,framelayout

I have tried & come up with a solution. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" tools:context=".HomePage"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/mod_minecraft" android:scaleType="fitXY"> </ImageView> <LinearLayout android:orientation="vertical"...

ImageButton Not clickable - AndroidStudio

java,android,android-layout,android-studio

You are using PNG images as background. You should use the android:src attribute instead of android:background to get the touch feedback when the button is being clicked. If you want to change the background you must use an XML drawable selector. See the docs

How to make image distributed to screen width in RelativeLayout?

android,android-layout,relativelayout,android-relativelayout

Please use LinearLayout and use this code, which will work in all resolutions device. <?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:gravity="center_horizontal" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="3" > <ImageView android:id="@+id/icon1"...

Accessing shared preferences in a non-activity class from fragment class

java,android,android-layout,android-fragments

Calling getActivity() is fine, it will resolve to a Context. You don't need the full getActivity().getApplicationContext(). This may cause a problem since you're telling Android to use the context of the application instead of the current Activity. Someday you'll appreciate this. Besides that, you NEED to create instance of dailyQuranMethods....

RadioGroup and TextView in a RelativeLayout - RadioGroup is hiding TextView

android,android-layout,android-radiogroup

Adding XML that is working as expected for posterity <?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" android:orientation="horizontal" > <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height=“wrap_content” > </ListView> <TextView android:id="@+id/sample" android:layout_width="match_parent"...

Layout occupies more than desired

android,android-layout,relativelayout

The problem is this line: android:layout_below="@+id/zoom_out" Take out that and then alignt to base line the images. ...

marquee text of textview in actionbar not marquee anyone after setText

android,android-layout,android-textview

After setting the text, add the following mTitleTextView.setSelected(true); mTitleTextView.setEllipsize(TruncateAt.MARQUEE); ...

Floating action button in ViewPager above a listView

android,android-layout,listview

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include android:id="@+id/tool_bar" layout="@layout/tool_bar" android:layout_width="match_parent" android:layout_height="wrap_content" />...

Aligning layout to fit all screen size

java,android,xml,android-layout

Chnage background to src "android:src="@drawable/mealbreakfast"" <ImageView android:id="@+id/breakfastview" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/mealbreakfast" android:clickable="true" android:onClick="onClick" android:scaleType="center" /> ...

An activity with two listviews in android

android,android-layout,android-activity,layout,android-listview

Your problem is with your RelativeLayout under your ScrollView. Try replacing it with a vertical LinearLayout and give its 2 child LinearLayout a weight of 1 like this: <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" > <LinearLayout android:id="@+id/LinearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/ll" android:layout_width="fill_parent"...