PopupWindow的應用以及漸變背景

簡要:popupwindow的使用以及漸變背景,增加層次感。
效果:
這裏寫圖片描述

實現很簡單,直接上代碼:

View view = View.inflate(this, R.layout.popupwindow_add, null);
        PopupWindow popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable()); //這個必須設置,如果不設置,點擊外面popupwindow消失
        popupWindow.showAsDropDown(v);

漸變背景drawable代碼:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 
        shape是用來定義形狀的,
        gradient定義該形狀裏面爲漸變色填充,
        startColor起始顏色,
        endColor結束顏色,
        angle表示方向角度。
                當angle=0時,漸變色是從左向右。 然後逆時針方向轉,當angle=90時爲從下往上。
     -->
    <gradient
        android:angle="45"
        android:endColor="@color/color_primary"
        android:startColor="#97CBFF" />

</shape>

popupwindow的界面xml

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

    <LinearLayout
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingRight="12dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bg"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/re_username"
                android:layout_width="match_parent"
                android:layout_height="48dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:text="test1"
                    android:textColor="#fff"
                    android:textSize="16sp" />
            </RelativeLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:background="#97CBFF" />

            <RelativeLayout
                android:id="@+id/re_online_feedback"
                android:layout_width="match_parent"
                android:layout_height="48dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:layout_centerVertical="true"
                    android:text="在線反饋"
                    android:textColor="#fff"
                    android:textSize="16sp" />
            </RelativeLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:background="#97CBFF" />

            <RelativeLayout
                android:id="@+id/re_app_exit"
                android:layout_width="match_parent"
                android:layout_height="48dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:layout_centerVertical="true"
                    android:text="退出"
                    android:textColor="#fff"
                    android:textSize="16sp" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

源碼下載

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章