2

プログラムでアプリケーションウィンドウを非表示にするにはどうすればよいですか?

出来ますか?

setContentView( R.layout.screen1 );

アプリケーションウィンドウを開始するためのこのコーディング。このウィンドウを非表示にする方法。出来ますか?

ありがとう。

4

2 に答える 2

4

これで試してみてください、

MainActivity.java

        public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Put you code to hide the layout
        RelativeLayout mLayout = (RelativeLayout) findViewById(R.id.mainLayout);
        mLayout.setVisibility(View.GONE);
    }
}

activity_main.xml

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="96dp"
        android:text="Button" />

</RelativeLayout>
于 2012-07-09T11:50:42.453 に答える
1

ええ、その可能性。次のように、screen1レイアウトの親ウィンドウにIDを指定します。

android:id="@+id/main_layout"

非表示にする場合は、次のように記述します。

final LinearLayout mainLayout = (LinearLayout)findViewById(R.layout.main_layout); // assuming its a LinearLayout

mainLayout.setVisibility(View.GONE);
于 2012-07-09T11:52:10.997 に答える