首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为android用户说明使用overlays

为android用户说明使用overlays
EN

Stack Overflow用户
提问于 2013-12-10 20:52:48
回答 1查看 776关注 0票数 0

嗨,我试图添加一个简单的覆盖到我的应用程序来突出显示比特和鲍勃给用户,我目前正在遵循这个简短的指南http://www.christianpeeters.com/android-tutorials/android-tutorial-overlay-with-user-instructions/,但我得到一个错误使用安卓工作室无法解决变量topLeveLayout我是一个完全的初学者,并已尝试让这移动任何建议?

下面是我的xml

代码语言:javascript
复制
<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" >


<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:text="@string/bath2"
    android:id="@+id/bath_text_View"
    android:textSize="23sp"
    android:gravity="center"
    android:textStyle="bold|italic" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/bath_text_View"
    android:contentDescription="@string/bathable2"
    android:src="@drawable/pic5"
    android:layout_above="@+id/nextbutton"
    android:id="@+id/imageView"
    android:scaleType="centerCrop"
    android:cropToPadding="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/next"
    android:id="@+id/nextbutton"
    android:textSize="20sp"
    android:textStyle="bold|italic"
    android:layout_gravity="center"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:onClick="nextImage2"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button2"
    android:background="@android:color/transparent"
    android:layout_above="@+id/button4"
    android:layout_centerHorizontal="true" />

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button4"
    android:background="@android:color/transparent"
    android:layout_above="@+id/button"
    android:layout_alignParentLeft="true"
    android:clickable="false" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="invisible"
    android:id="@+id/button"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true" />

</RelativeLayout>
<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:contentDescription="@string/overlay"
        android:src="@drawable/hint_menu" />

</RelativeLayout>

</FrameLayout>

因此,我在一个框架布局中有两个相对布局,第一个是我的应用程序,第二个是覆盖图

这是我的.java

代码语言:javascript
复制
public class bathactivity2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bath_2);
    topLevelLayout = findViewById(R.id.top_layout);

    if (isFirstTime()) {
        topLevelLayout.setVisibility(View.INVISIBLE);
    }



    Button button2 = (Button) findViewById(R.id.button2);
    Button button4 = (Button) findViewById(R.id.button4);



    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaPlayer mp = MediaPlayer.create(bathactivity2.this, R.raw.rubber_duck);
            mp.start();
        }
    });

    button4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaPlayer mp = MediaPlayer.create(bathactivity2.this, R.raw.bubbles);
            mp.start();
        }
    });

}

public void nextImage2(View view){
    Intent intent = new Intent(this, BathActivity3.class);
    startActivity(intent);
}

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;

}
}

这只是一个带有几个隐藏按钮的图像,因此我想要一个覆盖图来指出按钮的位置,我得到错误,无法解析topLevelLayout无法解析运动事件和其他,这只是一个首先声明这些的情况,如果是这样的话?它是不是像这样

代码语言:javascript
复制
Layout topLevelLayout;    

还是有什么更糟糕的事情发生了谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2013-12-14 09:11:56

View topLevelLayout;这解决了它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20495116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档