Android 实现抖音头像底部弹框效果的实例代码
程序员文章站
2023-11-09 19:58:58
布局文件activity_test.xml
布局文件
activity_test.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <linearlayout android:id="@+id/linearlayout" android:orientation="vertical" app:layout_constraintstart_tostartof="parent" app:layout_constraintbottom_tobottomof="parent" android:background="@color/coloraccent" android:layout_width="match_parent" android:layout_height="300dp"> </linearlayout> <view android:layout_width="match_parent" android:layout_height="100dp" app:layout_constrainttop_totopof="@+id/linearlayout" app:layout_constraintbottom_totopof="@+id/linearlayout" app:layout_constraintstart_tostartof="parent" app:layout_constraintend_toendof="parent" android:alpha="0" android:background="@android:color/white" /> <imageview android:id="@+id/image" android:src="@mipmap/ic_launcher" app:layout_constrainttop_totopof="@+id/linearlayout" app:layout_constraintbottom_totopof="@+id/linearlayout" app:layout_constraintstart_tostartof="parent" app:layout_constraintend_toendof="parent" android:layout_margintop="100dp" android:layout_width="100dp" android:layout_height="100dp"/> </androidx.constraintlayout.widget.constraintlayout>
mainactivity.java
点击事件
view contentview = layoutinflater.from(mainactivity.this).inflate(r.layout.activity_test, null); popupwindow popwnd = new popupwindow(mainactivity.this); popwnd.setcontentview(contentview); popwnd.setwidth(viewgroup.layoutparams.match_parent); popwnd.setheight(viewgroup.layoutparams.wrap_content); popwnd.setbackgrounddrawable(new colordrawable(0x00000000)); popwnd.setoutsidetouchable(false); popwnd.setfocusable(true); //相对于父控件的底部显示 无任何偏移 popwnd.showatlocation(v, gravity.bottom, 0, 0);
到此这篇关于android 实现抖音头像底部弹框效果的文章就介绍到这了,更多相关android 抖音弹框内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!