【问题标题】:android SDK, one time welcome layoutandroid SDK,一次性欢迎布局
【发布时间】:2014-11-02 03:30:21
【问题描述】:

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

【问题讨论】:

    标签: android layout sdk screens


    【解决方案1】:

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

    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);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多