2014-11-07 2 views
5

댓글 버튼을 누르면 열리는 facebook android 앱과 같은 팝업 상자를 만들고 싶습니다. 내 응용 프로그램에 대해 같은 종류의 팝업을 디자인하고 싶습니다. 누구든지 저에게 건축 할 수있는 방법을 알려주거나 저에게 그런 종류의 것을 디자인하는 요구 사항이 무엇인지 알려줄 수 있습니까?안드로이드에서 팝업과 같은 페이스 북 코멘트를 작성하는 방법은 무엇입니까?

감사합니다.

+1

를 사용하여 사용자 정의 대화. –

+0

이 http://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android를 사용하고 대화 상자에 'edittext'을 입력하십시오. –

+0

제안 해 주셔서 감사합니다. –

답변

7

당신이

PopupWindow 여기

를 통해 달성 할 수있는 활동이나 조각을 통해 팝업 창을 호출하는 절차입니다. 굉장한 스윙 애니메이션을 위해 Rebound Library을 사용하는 페이스 북. 하지만 난 그것에 대한 정상적인 XML 애니메이션 파일을 사용했습니다.

<!-- PopuP Enter Exit Animation --> 
    <style name="PopupAnimation" parent="Widget.AppCompat.PopupWindow"> 
     <item name="android:windowEnterAnimation">@anim/bottom_up</item> 
     <item name="android:windowExitAnimation">@anim/bottom_down</item> 
    </style> 

자바 방법은 레이아웃에 목록을 추가하는 PopUpWindow

// call this method when required to show popup 
    public void onShowPopup(View v){ 

     LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     // inflate the custom popup layout 
     inflatedView = layoutInflater.inflate(R.layout.popup_layout, null,false); 
     // find the ListView in the popup layout 
     ListView listView = (ListView)inflatedView.findViewById(R.id.commentsListView); 
     LinearLayout headerView = (LinearLayout)inflatedView.findViewById(R.id.headerLayout); 
     // get device size 
     Display display = getWindowManager().getDefaultDisplay(); 
     final Point size = new Point(); 
     display.getSize(size); 
//  mDeviceHeight = size.y; 
     DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); 
     int width = displayMetrics.widthPixels; 
     int height = displayMetrics.heightPixels; 


     // fill the data to the list items 
     setSimpleList(listView); 


     // set height depends on the device size 
     popWindow = new PopupWindow(inflatedView, width,height-50, true); 
     // set a background drawable with rounders corners 
     popWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.popup_bg)); 

     popWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); 
     popWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); 

     popWindow.setAnimationStyle(R.style.PopupAnimation); 

     // show the popup at bottom of the screen and set some margin at bottom ie, 
     popWindow.showAtLocation(v, Gravity.BOTTOM, 0,100); 
} 

방법을 style.xml에서

popup_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/headerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:orientation="horizontal" 
     android:layout_alignParentTop="true" 
     android:gravity="center"> 

     <TextView 
      android:layout_gravity="center" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Some One and 20 Others Like this" 
      android:textColor="@color/black" 
      android:textStyle="bold" 
      android:layout_margin="5dp"/> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/commentsListView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/headerLayout" 
     android:layout_above="@+id/comment_section" 
     android:layout_marginBottom="0dp"/> 

    <LinearLayout 
     android:id="@+id/comment_section" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="5dp" 
     android:orientation="horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:gravity="center" 
     > 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:maxHeight="30dp" 
      android:minHeight="20dp" 
      android:layout_gravity="center" 
      android:src="@mipmap/ic_launcher" 
      /> 
     <EditText 
      android:id="@+id/writeComment" 
      android:hint="Write a Comment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:maxLines="2" 
      android:focusable="true" 
      android:layout_marginLeft="2dp" 
      android:textSize="12sp" 
      android:textColor="@color/black" 
      android:background="#00000000"/> 

    </LinearLayout> 

</RelativeLayout> 

팝업 애니메이션을 호출하는

,941,765,242,

애니메이션 파일 bottom_up.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate android:fromYDelta="75%p" android:toYDelta="0%p" 
     android:fillAfter="true" 
     android:duration="400"/> 
</set> 

bottom_down.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 

    <translate android:fromYDelta="0%p" android:toYDelta="100%p" android:fillAfter="true" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:duration="400" /> 

</set> 
+0

고맙습니다. 당신의 구현이 마음에 들지만, dismis에 대한 스윕을 도울 수 있습니까? – suulisin

+0

@Pamparanpa 아래로 스 와이프하여 팝업 해제 솔루션을 찾았습니까? – Dharmishtha

관련 문제