android – 以编程方式调整布局(作为动画)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – 以编程方式调整布局(作为动画),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1709字,纯文字阅读大概需要3分钟。
内容图文
![android – 以编程方式调整布局(作为动画)](/upload/InfoBanner/zyjiaocheng/715/5956786121894665be641b544e55cc6a.jpg)
我想在Activity中调整一些布局的大小.
这是主XML的代码:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/top"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#3ee3e3" >
</LinearLayout>
<LinearLayout
android:id="@+id/middle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#fe51e6" >
</LinearLayout>
</LinearLayout>
如您所见,顶部和底部布局高度为0,中间
布局涵盖了所有的地方.
我想以编程方式减少中间布局大小,同时增加顶部
和底部布局大小,直到所有布局具有相同的高度.
我希望它看起来像一个动画.
我该怎么办?
谢谢
解决方法:
我为了类似的目的写了一个ResizeAnimation.它很简单但成本很高.
/**
* an animation for resizing the view.
*/
public class ResizeAnimation extends Animation {
private View mView;
private float mToHeight;
private float mFromHeight;
private float mToWidth;
private float mFromWidth;
public ResizeAnimation(View v, float fromWidth, float fromHeight, float toWidth, float toHeight) {
mToHeight = toHeight;
mToWidth = toWidth;
mFromHeight = fromHeight;
mFromWidth = fromWidth;
mView = v;
setDuration(300);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float height =
(mToHeight - mFromHeight) * interpolatedTime + mFromHeight;
float width = (mToWidth - mFromWidth) * interpolatedTime + mFromWidth;
LayoutParams p = mView.getLayoutParams();
p.height = (int) height;
p.width = (int) width;
mView.requestLayout();
}
}
内容总结
以上是互联网集市为您收集整理的android – 以编程方式调整布局(作为动画)全部内容,希望文章能够帮你解决android – 以编程方式调整布局(作为动画)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。