Android FrameLayout 예제
MainAcitivity.java
|
package com.example.test2;
import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity implements OnClickListener { Button button1; Button button2; Button button3;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1 = (Button)findViewById(R.id.button1); button2 = (Button)findViewById(R.id.button2); button3 = (Button)findViewById(R.id.button3);
button1.setOnClickListener(this); button2.setOnClickListener(this); button3.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) { View temp; // TODO Auto-generated method stub if( v.getId() == R.id.button1 ) { temp = (View)findViewById(R.id.tab1); temp.setVisibility(View.VISIBLE); temp = (View)findViewById(R.id.tab2); temp.setVisibility(View.INVISIBLE); temp = (View)findViewById(R.id.tab3); temp.setVisibility(View.INVISIBLE); } else if( v.getId() == R.id.button2 ) { temp = (View)findViewById(R.id.tab2); temp.setVisibility(View.VISIBLE); temp = (View)findViewById(R.id.tab1); temp.setVisibility(View.INVISIBLE); temp = (View)findViewById(R.id.tab3); temp.setVisibility(View.INVISIBLE); } else if( v.getId() == R.id.button3 ) { temp = (View)findViewById(R.id.tab3); temp.setVisibility(View.VISIBLE); temp = (View)findViewById(R.id.tab1); temp.setVisibility(View.INVISIBLE); temp = (View)findViewById(R.id.tab2); temp.setVisibility(View.INVISIBLE); }
}
} |
activity_main.xml
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Button1" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button2" android:layout_alignBottom="@+id/button2" android:layout_toRightOf="@+id/button2" android:text="Button3" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/button1" android:text="Button2" /> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/button2"> <ImageView android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/image" /> <LinearLayout android:id="@+id/tab2" android:visibility="invisible" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> <LinearLayout android:id="@+id/tab3" android:visibility="invisible" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </TableRow> <TableRow> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </TableRow> </TableLayout> </LinearLayout> </FrameLayout> </RelativeLayout> |
'Programming > Android' 카테고리의 다른 글
Android GoogleMap API V2 (0) | 2014.01.19 |
---|---|
viewpagertest (0) | 2014.01.14 |
안드로이드 위치 기록, 위치 추적 (0) | 2014.01.12 |
Windows 7 환경에서 Android Fulll Source 다운로드 받기 (0) | 2013.11.20 |
android-screenshot-library 라이브러리 사용하기 (1) | 2013.11.14 |