我想创建帮助叠加层,就像你第一次加载ICS时看到的那样,或者在ES File Explorer或Apex Launcher等应用程序中加载(有更多,但我现在想不到它们).这只是一个相对布局,一个视图位于另一个视图的顶部吗?我无法找到任何用于执行此类操作的示例代码.任何人都知道这是如何完成或有任何想法?

Com*_*are 84
我们假设您通常会打电话setContentView(R.layout.main),但在第一次运行时,您希望拥有此叠加层.
步骤1:创建一个FrameLayoutJava代码并将其传递给setContentView().
第二步:LayoutInflater用来膨胀R.layout.main到FrameLayout.
步骤#3:用于LayoutInflater将叠加层膨胀到FrameLayout.
步骤#4:当用户点击按钮(或其他)以关闭覆盖图时,请致电removeView()以从中移除覆盖图FrameLayout.
由于叠加层是后来的子窗口FrameLayout,它将浮动在内容的顶部R.layout.main.
Ode*_*ner 80
用户体验谈话中的"教练标记"是"帮助叠加":-)
coach_mark.xml是您的教练标记布局
coach_mark_master_view是coach_mark.xml中最顶层视图(root)的id
public void onCoachMark(){
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.coach_mark);
dialog.setCanceledOnTouchOutside(true);
//for dismissing anywhere you touch
View masterView = dialog.findViewById(R.id.coach_mark_master_view);
masterView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
Run Code Online (Sandbox Code Playgroud)
添加coach_mark.xml的样本(由Oded Breiner给出的这个优秀的解决方案),因此很容易让ppl复制和粘贴以快速查看工作示例.
这里是coach_mark.xml的示例,将 - > drawable/coach_marks更改为您的图像:
coach_mark.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/coach_mark_master_view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/coach_marks_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:src="@drawable/coach_marks" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
并可选择使用此主题删除填充:
<style name="WalkthroughTheme" parent="Theme.AppCompat">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49608 次 |
| 最近记录: |