如何建立像在android系统弹出一个Facebook的评论? [英] how to build a facebook comment like popup in android?

查看:134
本文介绍了如何建立像在android系统弹出一个Facebook的评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出像Facebook Android应用程序一个弹出框,其中上pressing的评论按钮打开。我想设计同类弹出我的应用程序。任何人都可以让我知道如何可以建立或只是引导我什么是设计之类的话的要求。

I would like to make a popup box like facebook android app which opens up on pressing the comments button. i want to design the same kind of pop-up for my application . Can anyone let me know how it can be build or just guide me what is the requirement to design that kind of thing.

感谢。

推荐答案

您可以通过

PopupWindow

PopupWindow

下面是过度活动或片段调用弹出窗口的过程。
Facebook的使用反弹真棒挥杆动画库。但我用正常的XML动画文件为。

Here is the procedure of calling popup window over activity or fragment. Facebook using Rebound Library for awesome swing animations. But i used normal xml animation files for that.

popup_layout.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>

在弹出style.xml动画

popup Animation in style.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>

Java方法调用PopUpWindow

Java Method to call 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);
}

添加到列表布局方法

Method for adding list into layout

  void setSimpleList(ListView listView){

        ArrayList<String> contactsList = new ArrayList<String>();

        for (int index = 0; index < 10; index++) {
            contactsList.add("I am @ index " + index + " today " + Calendar.getInstance().getTime().toString());
        }

        listView.setAdapter(new ArrayAdapter<String>(MainActivity.this,
                R.layout.popup_list_item, android.R.id.text1, contactsList));
    }

动画文件
bottom_up.xml

Animation File 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

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>

这篇关于如何建立像在android系统弹出一个Facebook的评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆