Android碎纸机效果
2024-08-30 16:25:26
1.总体思想
活用padding和margin
2.实现过程
public class PopupShredderView extends FrameLayout{
public PopupShredderView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle);
init();
} public PopupShredderView(Context context, AttributeSet attrs) { super(context, attrs);
init() ;
} public PopupShredderView(Context context) { super(context);
init();
} private void init(){
final LayoutInflater layoutInflater = LayoutInflater.from(context);
mView = layoutInflater.inflate(R.layout.popup_shredder_clean, this, false); mCleanText1.setImageDrawable(themeManager.getDrawable(R.drawable.exit_clean_date));
mCleanText2.setBackgroundDrawable(themeManager.getDrawable(R.drawable.exit_clean_result));
mCleanText2.setVisibility(View.INVISIBLE);
} public void update(int step, int offset){
if (step == STEP_END) {
return;
}
int clean1Offset = mCleanText1.getMeasuredHeight() * step / STEP_END;
int maxClean1Offset=mCleanText1.getMeasuredHeight();
if (offset + clean1Offset < maxClean1Offset) {
clean1Offset = clean1Offset + offset;
} else {
clean1Offset = maxClean1Offset;
}
mCleanText1.setPadding(0, clean1Offset, 0, 0);
mCleanText2.setVisibility(View.VISIBLE);
int clean2Offset = ((View) mCleanText2.getParent()).getMeasuredHeight() * (STEP_END - step)
/ STEP_END;
int maxClean2Offset= 0;
if (clean2Offset - offset > maxClean2Offset) {
clean2Offset = clean2Offset - offset;
} else {
clean2Offset = maxClean2Offset;
}
LinearLayout.LayoutParams layoutParams = (android.widget.LinearLayout.LayoutParams) mCleanText2
.getLayoutParams();
layoutParams.bottomMargin = clean2Offset;
mCleanText2.setLayoutParams(layoutParams);
invalidate();
} }
3.布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menubar"
android:layout_width="192dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" > <ImageView
android:id="@+id/exit_clean1"
android:layout_width="wrap_content"
android:layout_height="@dimen/popup_shredder_top_heigh"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="21dp"
android:contentDescription="@string/app_name"
android:scaleType="matrix" /> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="@dimen/popup_shredder_top_heigh"
android:layout_marginLeft="28dp"
android:layout_marginTop="@dimen/popup_shredder_bottom_top_margin"
android:orientation="vertical" > <ImageView
android:id="@+id/exit_clean2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/app_name" />
</LinearLayout> <ImageView
android:id="@+id/exit_clean3"
android:layout_width="wrap_content"
android:layout_height="@dimen/popup_shredder_delete_heigh"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/popup_shredder_delete_top_margin"
android:contentDescription="@string/app_name" /> </RelativeLayout>
最新文章
- [LeetCode] Rearrange String k Distance Apart 按距离为k隔离重排字符串
- 第一个web框架tornado
- 【BZOJ】3737: [Pa2013]Euler
- React Native 简介:用 JavaScript 搭建 iOS 应用(2)
- 监听某个div或其它标签的大小改变来执行相应的处理
- 步步为营 SharePoint 开发学习笔记系列总结
- 《A First Course in Abstract Algebra with Applications》-chaper1-数论
- CountDownLatch的使用
- 管理 sendmail 的邮件队列
- jquery 监听回车提交
- 65、django之模型层(model)--添加、单表查询、修改基础
- React Native:真机断点调试+跨域资源加载出错问题解决
- CentOS添加磁盘分区
- 在&#39;for&#39;循环中获取索引
- FFmpeg 学习(三):将 FFmpeg 移植到 Android平台
- gRPC奇怪的编译命令protoc
- calloc()的使用
- ubuntu上编译linux内核
- sh-copy-id命令报错:-bash: ssh-copy-id: command not found
- zookeeper集群搭建 windows