Android Animation disabled EditText - android

i add the Bounce effect to Linear layout.This linear layout contain 2 EditTexts and one button.but when animation complete Edittexts and Button are Disabled.I cant use them.how can i enable Edittexts and Button.
XML
<LinearLayout android:background="#drawable/login_grd" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="50dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:textSize="55sp"
android:gravity="center"
android:layout_gravity="center"
android:textColor="#fff"
android:id="#+id/_title"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AFF"/>
<Button
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="200dp"
android:textColor="#000"
android:background="#fff"
android:id="#+id/animloginButton"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Login"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="480dp"
android:background="#color/white"
android:id="#+id/lnr_do_login"
android:layout_marginTop="280dp">
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel2"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:id="#+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:textSize="16sp"
android:textColor="#color/black"
android:id="#+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel2"
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<EditText
android:textSize="16sp"
android:textColor="#color/black"
android:inputType="textPassword"
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password" />
</android.support.design.widget.TextInputLayout>
<Button
android:textColor="#000"
android:background="#fff"
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Sign In"/>
</LinearLayout>
<TextView
android:textColor="#color/white"
android:layout_gravity="bottom|right"
android:gravity="bottom|center"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="#string/app_name"
android:layout_marginBottom="10dp" />
</LinearLayout>
</LinearLayout>
LoginActivity.class
private LinearLayout lnrLoginView;
#Override
public void onCreate(Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(R.layout.before_login_screen);
animloginButton = (Button) findViewById(R.id.animloginButton);
lnrLoginView = (LinearLayout) findViewById(R.id.lnr_do_login);
TextView title = (TextView) findViewById(R.id._title);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/title_font.ttf");
title.setTypeface(type);
animloginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
lnrLoginView.clearAnimation();
TranslateAnimation translation;
translation = new TranslateAnimation(0f, 0F, 0f, -getDisplayHeight());
translation.setStartOffset(10);
translation.setDuration(1000);
translation.setFillAfter(true);
translation.setInterpolator(new BounceInterpolator());
lnrLoginView.startAnimation(translation);
animloginButton.setVisibility(View.INVISIBLE);
}
private int getDisplayHeight() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics.widthPixels;
}
});
}

Try to use ObjectAnimator.onFloat instead.
animloginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(lnrLoginView.getTag() instanceof Animator){
((Animator)lnrLoginView.getTag()).cancel();
}
ObjectAnimator translateY = ObjectAnimator
.ofFloat(target, "translationY", -transY)
.setDuration(1000)
;
translateY.setStartDelay(10);
translateY.setTarget(lnrLoginView);
translateY.setInterpolator(new BounceInterpolator());
translateY.start();
animloginButton.setVisibility(View.INVISIBLE);
}
private int getDisplayHeight() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics.widthPixels;
}
});

Use a animation listener to malipulate your views before and after the animation.
translation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
//Disable the views.
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
//Enable the views
}
});

Related

Slide up animation not working correctrly

I have one Linearlayout.Here is a my xml code
<LinearLayout
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-4dp">
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/paper_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:src="#mipmap/ic_app_icon" />
<TextView
android:id="#+id/company_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:singleLine="true"
android:text="Company Name"
android:textColor="#android:color/black"
android:textSize="30dp" />
<TextView
android:id="#+id/company_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:singleLine="true"
android:text="Company Address"
android:textColor="#android:color/black"
android:textSize="14dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="10dp"
android:focusableInTouchMode="false"
android:listSelector="#00000000"
android:overScrollMode="never"
android:scrollbars="none" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:src="#mipmap/test_img" />
<View
android:layout_width="match_parent"
android:layout_height="16dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
I goal is to create bottom to top animation.I wrote some code ,but animation does not working correctly. Here is a my java code.
In Activity's onCreate method
slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -5.0f);
slide.setDuration(4000);
slide.setFillAfter(true);
slide.setFillEnabled(true);
I try to start animation like this
if (slide != null) {
linearLayout.startAnimation(slide);
slide.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
linearLayout.clearAnimation();
startActivity(MainActivity.class);
}
});
}
My goal is to start another activity as soon as animation finish
public void startActivity(Class<?> cls) {
Intent intent = new Intent(this, cls);
startActivity(intent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
But,after 4 second,when animation has finished ,new activity does not working immediately.Is a any way to speed up calling new activity?
Try using this:
val animation = ObjectAnimator.ofFloat(layout, "translationY", 440f)
animation.duration = 4500
animation.interpolator = LinearInterpolator()
animation.addListener(AnimatorListenerAdapter() {
//animation end is here
// TODO
})
The code is in kotlin, but you can easily convert it

How to set zoom controls on TextView and ImageView

i want to set zoom controls on TextView and ImageView. where, when zoom in pressed then all the textview and imageview are being zoomed in, and when zoom out pressed all the textview and imageview are being zoomed out with the function of scrollable left & right.
or, is it possible pinch to zoom only in imageview?
my try is below, but not worked perfectly.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/activity_main"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:orientation="vertical"
tools:context="sample.app"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:orientation="vertical"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textIsSelectable="true"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="something in text view"
android:textColor="#ff0000"
android:textIsSelectable="true"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="another textview"
android:textColor="#000000"
android:textIsSelectable="true"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Parts list"
android:textColor="#ff0000"
android:textIsSelectable="true"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="#drawable/melody" />
</LinearLayout>
</ScrollView>
<ZoomControls
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/zoomControls"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
public class melodygenerator extends AppCompatActivity {
ZoomControls zoomit;
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.melodygenerator);
zoomit = (ZoomControls)findViewById(R.id.zoomControls);
imageView = (ImageView)findViewById(R.id.imageView);
zoomit.setOnZoomInClickListener(new View.OnClickListener(){
#Override
public void onClick(View V){
float x = imageView.getScaleX();
float y = imageView.getScrollY();
imageView.setScaleX ((int) (x+1));
imageView.setScaleY((int) (y+1));
}
});
zoomit.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View V) {
float x = imageView.getScaleX();
float y = imageView.getScrollY();
imageView.setScaleX ((int) (x-1));
imageView.setScaleY((int) (y-1));
}
});
}}
Try using this code.
public class melodygenerator extends AppCompatActivity {
ZoomControls zoomit;
ImageView imageView;
boolean isZoomeed;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.melodygenerator);
zoomit = (ZoomControls)findViewById(R.id.zoomControls);
imageView = (ImageView)findViewById(R.id.imageView);
zoomit.setOnZoomInClickListener(new View.OnClickListener(){
#Override
public void onClick(View V){
float x = imageView.getScaleX();
float y = imageView.getScrollY();
if(isZoomeed) {
isZoomeed = false;
imageView.setScaleX ((int) (x-1));
imageView.setScaleY((int) (y-1));
}else {
isZoomeed = true;
imageView.setScaleX ((int) (x+1));
imageView.setScaleY((int) (y+1));
}
}
});
}}

Android Auto Scroll when a Button is pressed

I have a XML Layout that puts a button at the bottom of the screen. I'd like to show a text under this button, when it is pressed, with a sort of auto scroll.
I really don't know how to do it. Any suggestion?
My XML file:
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.thefe.newsmartkedex.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/pkmn"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="#+id/tmpPkmn" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/tipo"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/tmpPkmn"
android:layout_marginStart="19dp"
android:layout_marginTop="89dp"
android:id="#+id/tipo1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/tipo"
android:id="#+id/tipo2"
android:layout_marginTop="20dp"
android:layout_below="#+id/tipo1"
android:layout_alignParentEnd="true"
android:layout_alignStart="#+id/tipo1" />
<TextView
android:text="Tipo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tipo"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="36dp"
android:textSize="20dp"
android:textAlignment="center"
android:layout_alignStart="#+id/tipo1" />
<TextView
android:text="Forte contro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:textSize="20dp"
android:id="#+id/forteContro" />
<TextView
android:text="Debole contro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/forteContro"
android:layout_marginTop="108dp"
android:textSize="20dp"
android:id="#+id/deboleContro" />
<!--tsf = tiposmallforte-->
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/forteContro"
android:id="#+id/tsf1"
android:src="#drawable/tipoSmall"/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/forteContro"
android:layout_toRightOf="#id/tsf1"
android:id="#+id/tsf2"
android:src="#drawable/tipoSmall"/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/forteContro"
android:layout_toRightOf="#id/tsf2"
android:id="#+id/tsf3"
android:src="#drawable/tipoSmall"/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/forteContro"
android:layout_toRightOf="#id/tsf3"
android:id="#+id/tsf4"
android:src="#drawable/tipoSmall"/>
<!--tsd = tiposmalldebole-->
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/deboleContro"
android:id="#+id/tsd1"
android:src="#drawable/tipoSmall"/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/deboleContro"
android:layout_toRightOf="#id/tsd1"
android:id="#+id/tsd2"
android:src="#drawable/tipoSmall"/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/deboleContro"
android:layout_toRightOf="#id/tsd2"
android:id="#+id/tsd3"
android:src="#drawable/tipoSmall"/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#id/deboleContro"
android:layout_toRightOf="#id/tsd3"
android:id="#+id/tsd4"
android:src="#drawable/tipoSmall"/>
<Button
android:text="Descrizione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:id="#+id/descrizione" />
</RelativeLayout>
First wrap everything inside a ScrollView
and now place your button and a textview inside a LinearLayout like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<Button
android:text="Descrizione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/descrizione" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:visibility="gone" />
</LinearLayout>
Now in button click action set your text to the textView and don't forget to change its visibility to visible. Finally scroll to the textView with scrollView.fullScroll(View.FOCUS_DOWN)
-----For Auto Scrolling webview click on Toggle Button ----
public class MainActivity extends AppCompatActivity {
TimerTask mTimerTask;
final Handler handler = new Handler();
Timer t = new Timer();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ToggleButton toggleButton = (ToggleButton)findViewById(R.id.toggleButton);
final WebView webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("https://en.wikipedia.org/wiki/Blog");
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean ischecked) {
if (ischecked) {
Toast.makeText(MainActivity.this,"Start AutoScrolling", Toast.LENGTH_SHORT).show();
doTimerTask(); }
else{
stopTask();
Toast.makeText(MainActivity.this,"Stop AutoScrolling", Toast.LENGTH_SHORT).show();
}
}
private void stopTask() {
mTimerTask.cancel();
}
private void doTimerTask() {
mTimerTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
webView.post(new Runnable() {
public void run() {
if (webView.getContentHeight() * webView.getScale() >= webView.getScrollY()) {
webView.scrollBy(0, 5);
}
}
});
}
});
}};
// public void schedule (TimerTask task, long delay, long period)
t.schedule(mTimerTask, 0, 500);
}
});
}
}

Make Fragment Grows and Show More Info

my application have 2 fragments:
1 - Have several fields to insert info for a query, and initially it shows only a field to input the name and a button that make it grows;
2 - A list view that would show the results for the query.
I'm using Visibility.GONE to make the trick (not show the other fields, and when the user press the button, they appear):
I have several of these
<android.support.v7.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.tcgapp.myrium.fowhelper.MainActivity"
tools:showIn="#layout/activity_main"
android:orientation="vertical"
android:id="#+id/fragment_search_area"
>
<!--android:background="#c94040" -->
<!-- Name of Card and button to expand the view-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/layout_name_search"
android:background="#android:color/darker_gray">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/label_name"
android:text="#string/name_label"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textStyle="bold"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_name"
android:hint="#string/name_hint"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:singleLine="true"
android:layout_weight="0.90" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button_expand"
android:src="#drawable/ic_arrow_downward_black_24dp" />
</LinearLayout>
<!-- Type Set and Format-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/search_tags_area"
android:orientation="horizontal"
android:background="#android:color/holo_blue_dark">
<Spinner
android:id="#+id/spinner_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<util.MultiSpinner
android:id="#+id/spinner_rarity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<util.MultiSpinner
android:id="#+id/spinner_set"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Spinner
android:id="#+id/spinner_format"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
</LinearLayout>
<!-- Card Text Field-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_card_text"
android:hint="#string/field_text"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<!-- Spinners-->
<!-- Attribute and choices-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/layout_attribute"
android:background="#android:color/darker_gray"
android:visibility="gone">
<util.MultiSpinner
android:id="#+id/multi_spinner_attribute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Spinner
android:id="#+id/spinner_choices_to_query_attribute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
</LinearLayout>
<!-- Now the query fields-->
<!-- Atk Def-->
<LinearLayout
android:id="#+id/layout_atkdef"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#75b194"
>
<TextView
android:id="#+id/text_atk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/field_atk"
android:gravity="left"
android:textStyle="bold"
android:layout_weight="2"
android:textSize="15sp"
android:paddingLeft="10dp"/>
<Spinner
android:id="#+id/spinner_atk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<android.support.v7.widget.AppCompatEditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="numberSigned"/>
<!-- Atk field-->
<TextView
android:id="#+id/text_def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/field_def"
android:gravity="left"
android:textStyle="bold"
android:layout_weight="2"
android:textSize="15sp"
android:paddingLeft="10dp"
/>
<Spinner
android:id="#+id/spinner_def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<android.support.v7.widget.AppCompatEditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="numberSigned"/>
</LinearLayout>
<!-- SubType and CMC-->
<LinearLayout
android:id="#+id/layout_subtype_cmc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="#75b194"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/field_subtype"
android:layout_weight="2"
android:textSize="15sp"
android:paddingLeft="10dp"
android:textStyle="bold"/>
<android.support.v7.widget.AppCompatEditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_weight="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/field_cmc"
android:layout_weight="1"
android:textSize="15sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/spinner_cmc"/>
</LinearLayout>
<!-- Card Flavor e Code-->
<LinearLayout
android:id="#+id/layout_flavor_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="#75b194"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/edit_card_flavor"
android:hint="#string/field_flavor"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_weight="1"
android:singleLine="true"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/edit_card_code"
android:hint="#string/field_code"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_weight="1"
android:singleLine="true"/>
</LinearLayout>
And on Java code, i have an animator object, and this is its AnimationEnd():
#Override
public void onClick(View v) {
int newWeight = isExpanded ? 0 : 60;
ViewWeightAnimationWrapper animationWrapper = new ViewWeightAnimationWrapper(getView());
ObjectAnimator anim = ObjectAnimator.ofFloat(animationWrapper,
"weight",
animationWrapper.getWeight(),
newWeight);
anim.setDuration(500);
anim.addListener(new AnimatorListenerAdapter() {
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
// if (!isExpanded){
// getView().findViewById(R.id.layout_atkdef).setVisibility(View.INVISIBLE);
// getView().findViewById(R.id.layout_subtype_cmc).setVisibility(View.INVISIBLE);
// getView().findViewById(R.id.layout_attribute).setVisibility(View.INVISIBLE);
// getView().findViewById(R.id.layout_flavor_code).setVisibility(View.INVISIBLE);
// }
}
#Override
public void onAnimationEnd (Animator animation){
super.onAnimationEnd(animation);
if (isExpanded) {
imageButtonToggle.setImageResource(R.drawable.ic_arrow_downward_black_24dp);
getView().findViewById(R.id.layout_atkdef).setVisibility(View.GONE);
getView().findViewById(R.id.layout_subtype_cmc).setVisibility(View.GONE);
getView().findViewById(R.id.layout_attribute).setVisibility(View.GONE);
getView().findViewById(R.id.layout_flavor_code).setVisibility(View.GONE);
} else {
imageButtonToggle.setImageResource(R.drawable.ic_arrow_upward_black_24dp);
getView().findViewById(R.id.layout_atkdef).setVisibility(View.VISIBLE);
getView().findViewById(R.id.layout_subtype_cmc).setVisibility(View.VISIBLE);
getView().findViewById(R.id.layout_attribute).setVisibility(View.VISIBLE);
getView().findViewById(R.id.layout_flavor_code).setVisibility(View.VISIBLE);
}
isExpanded = !isExpanded;
}
}
);
anim.start();
}
}
This is the way to hide the fields and show only when the user presses the expand button, or is a better way?
UPDATE: Providing full code.
Assuming you're asking if there's a nicer way of expanding/hiding an area with input, I'll share my implementation using your variables as best I can. I'll make some necessary notes as well.
//consider changing imageButtonToggle to a container view with an image in it
//in this example I'll use carrotImage as the image contained within imageButtonToggle
//formContainer contains all the views you're toggling from GONE to VISIBLE.
imageButtonToggle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!isExpanded) {
ViewAnimationHelper
.expand(formContainer, 300, false);
} else {
ViewAnimationHelper.collapse(formContainer, 300);
}
carrotImage.animate().rotation(ROTATION_COUNT);
ROTATION_COUNT += 180f;
//Silly check.. but better safe than sorry.
if (ROTATION_COUNT >= Float.MAX_VALUE)
ROTATION_COUNT = 0f;
isExpanded= !isExpanded;
}
});
public class ViewAnimationHelper {
/**
* Easy way to expand a given view after measuring with
* v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
*
* #param v
* #param duration
*/
public static void expand(final View v, int duration,
boolean bStartFromZeroHeight) {
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
if (bStartFromZeroHeight)
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
#Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
: (int) (targetHeight * interpolatedTime);
v.requestLayout();
}
#Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration(duration);
v.startAnimation(a);
}
/**
* Easy way to just collapse any given view and any given speed
*
* #param v
* #param duration
*/
public static void collapse(final View v, int duration) {
final int initialHeight = v.getMeasuredHeight();
Animation a = new Animation() {
#Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
v.getLayoutParams().height = initialHeight
- (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}
#Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration(duration);
v.startAnimation(a);
}
}

Layering of views during an objectanimation

I have a relative layout with a LinearLayout as a child viewgroup and a button as a child view. so when i press the button the linearlayout falls down the screen but it goes under the button , i want it to go over the button .
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="#+id/relative"
>
<LinearLayout
android:layout_width="365dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout"
android:background="#drawable/background">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Name"
android:ems="10"
android:id="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/radioButton"
android:layout_below="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/radioButton2"
android:layout_below="#+id/linearLayout"
android:layout_toRightOf="#+id/radioButton"
android:layout_toEndOf="#+id/radioButton" />
</RadioGroup>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Signup"
android:id="#+id/button"
android:layout_gravity="center"
android:translationZ="1dp"
android:layout_below="#+id/linearLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
my java code is :
public class MainActivity extends Activity {
ValueAnimator va;
LinearLayout linearLayout;
Button button;
ValueAnimator objectAnimator;
RelativeLayout relative;
boolean b=false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayout=(LinearLayout) findViewById(R.id.linearLayout);
button=(Button) findViewById(R.id.button);
setbuttonclick();
relative=(RelativeLayout) findViewById(R.id.relative);
relative.bringChildToFront(linearLayout);
}
public void setbuttonclick()
{
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(b==false) {
objectAnimator = ObjectAnimator.ofFloat(linearLayout, "TranslationY", 2600f);
objectAnimator.setDuration(1000);
objectAnimator.setInterpolator(new AnticipateOvershootInterpolator());
objectAnimator.start();
b=true;
}
else {
objectAnimator = ObjectAnimator.ofFloat(linearLayout, "TranslationY", 50f);
objectAnimator.setDuration(1000);
objectAnimator.setInterpolator(new AnticipateOvershootInterpolator());
objectAnimator.start();
b=false;
}
}
});
}
}

Categories

Resources