ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 윈도우 팝업을 이용한 CUSTOM 팝업 만들기
    안드로이드/학습&강좌 2011. 3. 27. 16:23

    첫 블로그를 개설해서 무엇을 올릴까 생각하다가, 최근에 만들던 윈도우 팝업을 먼저 올려 봅니다. ㅎ

    Dialog 와는 다르게 위치와 모양부분에서 포퍼먼스가 조금더 좋다고 생각하는데요, 물론 개인적인 입장입니다.

    Dialog도 꾸미게 되면 얼마든지 이쁘게 꾸밀 수 있겠죠.

    서두는 그만 두고 본론으로 들어 가도록 하겠습니다.

    Layout 부분 입니다. 팝업으로 만들 부분에 대해 레이아웃을 따로 지정해 줍니다.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:orientation="vertical"
     android:id="@+id/linear"
     android:background="@drawable/xxxxx"   // 따로 지정할 배경이미지를 만든부분 입니다.
     android:layout_height="wrap_content">
     <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
      <ImageView
       android:layout_width="120dip"
       android:layout_height="120dip"
       android:id="@+id/img"
       android:layout_marginLeft="5dip"
       android:layout_marginTop="5dip"
       android:layout_marginRight="5dip"
       android:layout_alignParentLeft="true" />
      <TextView
       android:id="@+id/name"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="5dip"
       android:text="홍길동"
       android:textSize="25dip"
       android:layout_toRightOf="@id/img" />
      <TextView
       android:id="@+id/hiwords"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_below="@id/name"
       android:layout_marginTop="5dip"
       android:textSize="15dip"
       android:layout_alignLeft="@id/name" />
      <ImageButton
       android:id="@+id/exit"
       android:background="@drawable/fd_am_delete_btn_s"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentRight="true" />
      <Button
       android:id="@+id/two_btnLeft"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="1:1채팅"
       android:textSize="15dip"
       android:layout_centerHorizontal="true"
       android:layout_marginLeft="20dip"
       android:layout_alignParentLeft="true"
       android:layout_alignParentBottom="true"
       android:layout_below="@id/img" />
      <Button
       android:layout_marginLeft="7dip"
       android:layout_centerHorizontal="true"
       android:id="@+id/two_btnRight"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textSize="15dip"
       android:layout_marginRight="20dip"
       android:layout_alignParentRight="true"
       android:layout_alignParentBottom="true"
       android:layout_below="@id/img"
       android:text="RIGHT" />
     </RelativeLayout>
    </LinearLayout>


    이 레이아웃 화면 구성입니다.




    이미지 부분 과 타이틀 / 종료 버튼 / 서브 타이틀 /
    버튼 두개로 구성한 상태입니다.

    띄울때의 코드 부분입니다.
    리스트목록에서 해당 행을 선택했을대 윈도우 팝업이 뜨도록 하였습니다.

    따로 만든게 아니고 프로젝트에 들어가있는 코드라 팝업부분만 보이도록 하겠습니다 ^^;;

    public class MemberListActivity extends Activity implements OnItemClickListener, OnTouchListener {
     

     ListView arr_list;
     
     LinearLayout linear;  // 팝업의 레이아웃 id
     View popupview;
     PopupWindow popup;
     
     @Override
     protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.memberlist);
      
    //  Log.d("myprofile_id", myprofile.getProf_id());
      myprofile = NootoGlobal.getPHONE();
      
     popupview = View.inflate(this, R.layout.popup_profile, null);
      popup = new PopupWindow(popupview, LayoutParams.FILL_PARENT, 270, true);
      popup.setOutsideTouchable(true); // 이부분을 설정해주어야 팝업이 떳을때 다른부분에 이벤트를 줄수있습니다.
      popup.setBackgroundDrawable(new BitmapDrawable());  // 이부분에 이벤트가 들어오게됩니다.
      
     }

    //아이템을 클릭했을때 팝업을 띄워주는 부분입니다.  

     @Override
     public void onItemClick(AdapterView<?> arg0, View arg1, int position,
       long arg3) {
      popup.showAtLocation(arg1, Gravity.BOTTOM | Gravity.CENTER, 0, 0);
    //  LinearLayout linear = (LinearLayout) View.inflate(
    //    MemberListActivity.this, R.layout.popup_profile, null);
    // 지정한 레이아웃을 가져옵니다.
    // 각각의 팝업마다 들어갈 이미지와 타이틀 / 서브타이틀~
      ImageView imageView = (ImageView) popupview.findViewById(R.id.img);
      TextView name = (TextView) popupview.findViewById(R.id.name);
      TextView hiwords = (TextView) popupview.findViewById(R.id.hiwords);
      Button btnleft = (Button) popupview.findViewById(R.id.two_btnLeft);
      Button btnrigth = (Button) popupview.findViewById(R.id.two_btnRight);
      ImageButton exit = (ImageButton)popupview.findViewById(R.id.exit);
      phonenum = list.get(position).getProf_phone();
      DrawImage.imgDisp(imageView, list.get(position).getProf_img());
      name.setText(list.get(position).getProf_name());
      hiwords.setText(list.get(position).getProf_hiword());
      btnrigth.setText(list.get(position).getProf_phone());
    //  
    //  //종료 버튼 
    //팝업 dismiss 종료 눌렀을때 팝업이 사라지게~
      exit.setOnClickListener(new OnClickListener() {
       
       @Override
       public void onClick(View v) {
        popup.dismiss();
       }
      });
    //  
    //  
    //  
    //  //전화 걸기
      btnrigth.setOnClickListener(new OnClickListener() {
       
       @Override
       public void onClick(View v) {
        startActivity(new Intent(Intent.ACTION_CALL,
          Uri.parse("tel:"+ phonenum)));
        popup.dismiss();
       }
      });
      index = position;
    //  
    //  //채팅방 입장
      btnleft.setOnClickListener(new OnClickListener() {
       
     // 생략합니다.
    //  new AlertDialog.Builder(MemberListActivity.this).setView(linear).show();

     }

      
     완성된 화면입니다.
     
     


    이상 리스트뷰에서 선택시 윈도우 팝업 생성 // 꾸미기 였습니다.

    처음으로 써보는 글이나 너무 두서도 없고, 생략된 코드도 많이 있습니다만, 팝업윈도우 자체를 이해하는데는 무리가 없을꺼 같네요, 글 연습좀 해야 겠습니다. ㅠ

    댓글

COPYRIGHT 2010 EpoNg. ALL RIGHTS RESERVED.