0

私のアプリには、アプリの仕組みと何ができるかを示すウェルカムレイアウトまたはヘルプレイアウトがあります。アプリのインストール時に一度だけ表示され、その後は表示されないようにしたいと思います。そして、これが可能である場合、それを行う最も簡単な方法は何ですか?

4

1 に答える 1

1

このようなことを試すことができます。2 つのレイアウトを作成します。メイン レイアウトとチュートリアル レイアウトをメイン ビューの上に重ねます。初めてかどうかを確認し、初めての場合はチュートリアルのレイアウトを表示する方法があります。初めてでない場合は、チュートリアルのレイアウトを非表示に設定してください。

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 に答える