动画按钮点击Android设备上查看 [英] Animate view on button click android
本文介绍了动画按钮点击Android设备上查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个按钮,该按钮我想below.That视图包含2个按钮,打开摄像头和gallery.To实现这个我已经使用转换动画幻灯片视图,但我没有得到期望的result.I唯一希望视图的重要的一部分是可见的幻灯片了。
动画code
<?XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=http://schemas.android.com/apk/res/android>
<翻译
机器人:fromYDelta = - 10%
机器人:toYDelta =0%
机器人:时间=1000/>
< /集>
code
公共类幻灯片扩展活动{ @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.slide);
按钮BT =(按钮)findViewById(R.id.button);
最终的LinearLayout的LinearLayout =(的LinearLayout)findViewById(R.id.test);
bt.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
动画幻灯片= AnimationUtils.loadAnimation(Slide.this,R.anim.top_slide);
//
linearLayout.startAnimation(幻灯片);
linearLayout.setVisibility(View.VISIBLE);
}
});
}
}
图片
我想滑应从+图像下方会出现,但它不是发生
XML code
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID /按钮
机器人:layout_gravity =CENTER_HORIZONTAL/> <的LinearLayout
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID /测试
机器人:知名度=水涨船高
机器人:layout_gravity =CENTER_HORIZONTAL> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID /按钮2/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID /按钮3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / butt3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / bton3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / butn3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / CB/> < / LinearLayout中>
< / LinearLayout中>
解决方案
您不需要幻灯片动画,你真正想要的是对象动画
code
按钮BT =(按钮)findViewById(R.id.button);
最终的LinearLayout的LinearLayout =(的LinearLayout)findViewById(R.id.test);
bt.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){ ValueAnimator动画= ValueAnimator.ofInt(linearLayout.getMeasuredHeight(),500);
anim.addUpdateListener(新ValueAnimator.AnimatorUpdateListener(){
@覆盖
公共无效onAnimationUpdate(ValueAnimator valueAnimator){
INT VAL =(整数)valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams的LayoutParams = linearLayout.getLayoutParams();
layoutParams.height = VAL;
linearLayout.setLayoutParams(的LayoutParams);
}
});
anim.setDuration(1000);
anim.start();
}
});
XML
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID /按钮
机器人:layout_gravity =CENTER_HORIZONTAL/> <的LinearLayout
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =0dp
机器人:ID =@ + ID /测试 机器人:背景=#fff333
机器人:layout_gravity =CENTER_HORIZONTAL> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID /按钮2/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID /按钮3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / butt3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / bton3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / butn3/> <按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=新按钮
机器人:ID =@ + ID / CB/> < / LinearLayout中>
< / LinearLayout中>
I have a button and on that button i wanna slide a view below.That view contains 2 buttons to open camera and gallery.To achieve this i have used translate animation but i am not getting the desired result.I want only that much part of the view to be visible as Slides down.
Anim Code
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="-10%"
android:toYDelta="0%"
android:duration="1000" />
</set>
Code
public class Slide extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide);
Button bt = (Button) findViewById(R.id.button);
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.test);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation slide = AnimationUtils.loadAnimation(Slide.this, R.anim.top_slide);
//
linearLayout.startAnimation(slide);
linearLayout.setVisibility(View.VISIBLE);
}
});
}
}
Image
i want the slide should occur from below the + image but its not happening
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/test"
android:visibility="gone"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/butt3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/bton3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/butn3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/cb" />
</LinearLayout>
</LinearLayout>
解决方案
you don't need slide animation, what you actually want is object animation
Code
Button bt = (Button) findViewById (R.id.button);
final LinearLayout linearLayout = (LinearLayout) findViewById (R.id.test);
bt.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View v) {
ValueAnimator anim = ValueAnimator.ofInt(linearLayout.getMeasuredHeight (), 500);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = linearLayout.getLayoutParams();
layoutParams.height = val;
linearLayout.setLayoutParams(layoutParams);
}
});
anim.setDuration(1000);
anim.start();
}
});
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/test"
android:background="#fff333"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/butt3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/bton3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/butn3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/cb" />
</LinearLayout>
</LinearLayout>
这篇关于动画按钮点击Android设备上查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文