0

因此,在我的应用程序中,我有一个欢迎布局或帮助布局,向您展示应用程序的工作原理以及它可以做什么,我希望它只在安装应用程序时显示一次,然后不再显示。如果这是可能的,那么最简单的方法是什么?

4

1 回答 1

1

你可以试试这样的。创建两个布局。你的主布局和你的教程布局覆盖在你的主视图之上。有一种方法可以检查它是否是第一次,如果是第一次则显示教程布局。如果不是第一次,请将教程布局设置为不可见。

isFirstTime() 方法

private boolean isFirstTime()
    {
    SharedPreferences preferences = getPreferences(MODE_PRIVATE);
    boolean ranBefore = preferences.getBoolean("RanBefore", false);
    if (!ranBefore) {

        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("RanBefore", true);
        editor.commit();
        topLevelLayout.setVisibility(View.VISIBLE);
        topLevelLayout.setOnTouchListener(new View.OnTouchListener(){

    @Override
    public boolean onTouch(View v, MotionEvent event) {
    topLevelLayout.setVisibility(View.INVISIBLE);
    return false;
    }

                });


        }
    return ranBefore;

    }

布局 XML

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main_layout" >

    <!--Below activity widgets when the transparent layout is gone -->

<RelativeLayout 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/gradient">

    <include
        android:id="@+id/include1"
        layout="@layout/actionbar" />

    <ImageView
        android:id="@+id/ivDressshirt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvLength"
        android:layout_marginTop="55dp"
        android:paddingLeft="@dimen/padding10dp"
        android:src="@drawable/shirt" />

</RelativeLayout>



    <!--Below is the transparent layout positioned at startup -->
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#88666666"
        android:id="@+id/top_layout">

    <ImageView
        android:id="@+id/ivInstruction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingTop="25dp"
        android:layout_marginRight="15dp"
        android:clickable="false"
        android:paddingLeft="20dip"
        android:scaleType="center"
        android:src="@drawable/help" />

    </RelativeLayout>

</FrameLayout>

onCreate()

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    topLevelLayout = findViewById(R.id.top_layout);



   if (isFirstTime()) {
        topLevelLayout.setVisibility(View.INVISIBLE);
    }
于 2014-09-08T20:10:38.390 回答