본문 바로가기

컴퓨터/android

버튼으로 탭 구현

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

<FrameLayout 

   android:layout_width="fill_parent"

   android:layout_height="0dp"

   android:layout_weight=".55">


<LinearLayout 

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

    android:id="@+id/lay_money">

</LinearLayout>


<LinearLayout 

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:orientation="vertical"

   android:id="@+id/lay_review">

</LinearLayout>


<LinearLayout

   android:id="@+id/lay_lost"

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:orientation="vertical" >

</LinearLayout>

</FrameLayout>


    <LinearLayout 

        android:layout_width="fill_parent"

        android:layout_height="0dp"

        android:layout_weight=".1"

        android:orientation="horizontal">

        <Button 

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight=".33"

            android:id="@+id/btn_money"

            android:text="요금정보"/>

        <Button 

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight=".33"

            android:id="@+id/btn_review"

            android:text="리뷰"/>

        <Button 

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight=".33"

            android:id="@+id/btn_lost"

            android:text="분실물"/>

    </LinearLayout>

</LinearLayout>




package com.example.hacka;


import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.view.*;

import android.widget.*;

import kr.pe.theeye.qrcode.R;


public class MainActivity extends Activity implements View.OnClickListener{

View page1,page2,page3;

Button btn1, btn2, btn3, btn4;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.taximain);

page1 = findViewById(R.id.lay_money);

page2 = findViewById(R.id.lay_review);

page3 = findViewById(R.id.lay_lost);

btn1 = (Button)findViewById(R.id.btn_money);

btn2 = (Button)findViewById(R.id.btn_review);

btn3 = (Button)findViewById(R.id.btn_lost);

btn4 = (Button)findViewById(R.id.btn_call);

page1.setVisibility(View.VISIBLE);

page2.setVisibility(View.INVISIBLE);

page3.setVisibility(View.INVISIBLE);


btn1.setOnClickListener(this);

btn2.setOnClickListener(this);

btn3.setOnClickListener(this);

btn4.setOnClickListener(this);

}

public void onClick(View v){

page1.setVisibility(View.INVISIBLE);

page2.setVisibility(View.INVISIBLE);

page3.setVisibility(View.INVISIBLE);

if(v.getId() == R.id.btn_money){

page1.setVisibility(View.VISIBLE);

}

else if(v.getId() == R.id.btn_review){

page2.setVisibility(View.VISIBLE);

}

else if(v.getId() == R.id.btn_lost){

page3.setVisibility(View.VISIBLE);

}

}

}








android:visibility="visible"      << 버튼을 보이고 싶을때
android:visibility="invisible"  << 버튼을 안보이고 싶을때(공간 차지함)

android:visibility="gone"  << 버튼을 안보이고 싶을때(공간 차지하지않음)



'컴퓨터 > android' 카테고리의 다른 글

ArrayList, ArrayAdapter, ListView  (0) 2013.07.05
체크박스  (0) 2013.07.01
WebView Manifest 추가  (0) 2013.04.30
RadioGroup 체크 확인할 때  (0) 2013.04.30
putExtra  (0) 2013.04.12