1. 程式人生 > >Android PopupWindow實現從頂部彈出下拉選單左、中、右

Android PopupWindow實現從頂部彈出下拉選單左、中、右

          本例項的自定義下拉選單主要是繼承PopupWindow類來實現的彈出窗體,各種佈局效果可以根據自己定義設計。彈出的動畫效果主要用到了translate、alpha、scale,具體實現步驟如下:

         先上效果圖如下:左邊下拉選單、中間下拉選單、右邊下拉選單

                 

1.主介面佈局 activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff" >

    <include
        android:id="@+id/main_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/urm_top" />

    <TextView
        android:id="@+id/rule_line_tv"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_below="@id/main_top"
        android:background="@color/reserve_line" />

    <LinearLayout
        android:id="@+id/main_ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/rule_line_tv"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:padding="10dp" >

        <TextView
            android:id="@+id/left_tv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:gravity="center_horizontal"
            android:maxLength="4"
            android:singleLine="true"
            android:text="我負責的線索" />

        <TextView
            android:id="@+id/middle_tv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:gravity="center_horizontal"
            android:maxLength="4"
            android:singleLine="true"
            android:text="團隊" />

        <TextView
            android:id="@+id/right_tv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:gravity="center_horizontal"
            android:maxLength="4"
            android:singleLine="true"
            android:text="自定義" />
    </LinearLayout>

    <TextView
        android:id="@+id/rule_line01_tv"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_below="@id/main_ll"
        android:background="@color/reserve_line" />

    <TextView
        android:id="@+id/main_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="主介面" />

</RelativeLayout>

2.主介面測試類 MainActivity.java
package com.popuptest;

import java.util.ArrayList;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RelativeLayout.LayoutParams;
import android.app.Activity;

public class MainActivity extends Activity implements OnClickListener {

	public static int screenW, screenH;

	private ImageButton backBtn, createBtn;
	private Button confirmBtn;
	private TextView topTv;
	private LinearLayout topll;
	private ImageView topIv;
	private TextView topLineTv;

	private TopMiddlePopup middlePopup;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		getScreenPixels();
		initWidget();
	}

	/**
	 * 初始化控制元件
	 */
	private void initWidget() {
		backBtn = (ImageButton) findViewById(R.id.urm_back_btn);
		createBtn = (ImageButton) findViewById(R.id.urm_create_btn);
		confirmBtn = (Button) findViewById(R.id.urm_confirm_btn);

		topll = (LinearLayout) findViewById(R.id.urm_top_ll);
		topIv = (ImageView) findViewById(R.id.urm_top_iv);

		topLineTv = (TextView) findViewById(R.id.rule_line_tv);

		topTv = (TextView) findViewById(R.id.urm_top_tv);
		topTv.setText("企業客戶");

		backBtn.setOnClickListener(this);
		createBtn.setOnClickListener(this);
		confirmBtn.setOnClickListener(this);
		topll.setOnClickListener(this);

	}

	/**
	 * 設定彈窗
	 * 
	 * @param type
	 */
	private void setPopup(int type) {
		middlePopup = new TopMiddlePopup(MainActivity.this, screenW, screenH,
				onItemClickListener, getItemsName(), type);
	}

	/**
	 * 設定彈窗內容
	 * 
	 * @return
	 */
	private ArrayList<String> getItemsName() {
		ArrayList<String> items = new ArrayList<String>();
		items.add("企業客戶");
		items.add("集團客戶");
		items.add("公海客戶");
		return items;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.urm_back_btn:
			setPopup(1);
			middlePopup.show(topLineTv);
			break;
		case R.id.urm_create_btn:
			setPopup(2);
			middlePopup.show(topLineTv);
			break;
		case R.id.urm_confirm_btn:

			break;
		case R.id.urm_top_ll:
			setPopup(0);
			middlePopup.show(topLineTv);
			break;
		}
	}

	/**
	 * 彈窗點選事件
	 */
	private OnItemClickListener onItemClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			System.out.println("--onItemClickListener--:");
			middlePopup.dismiss();
		}
	};

	/**
	 * 獲取螢幕的寬和高
	 */
	public void getScreenPixels() {
		DisplayMetrics metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		screenW = metrics.widthPixels;
		screenH = metrics.heightPixels;
	}

}

3.自定義彈窗類 TopMiddlePopup.java
package com.popuptest;

import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.AdapterView.OnItemClickListener;

public class TopMiddlePopup extends PopupWindow {

	private Context myContext;
	private ListView myLv;
	private OnItemClickListener myOnItemClickListener;
	private ArrayList<String> myItems;
	private int myWidth;
	private int myHeight;
	private int myType;

	// 判斷是否需要新增或更新列表子類項
	private boolean myIsDirty = true;

	private LayoutInflater inflater = null;
	private View myMenuView;

	private LinearLayout popupLL;

	private PopupAdapter adapter;

	public TopMiddlePopup(Context context) {
		// TODO Auto-generated constructor stub
	}

	public TopMiddlePopup(Context context, int width, int height,
			OnItemClickListener onItemClickListener, ArrayList<String> items,
			int type) {

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		myMenuView = inflater.inflate(R.layout.top_popup, null);

		this.myContext = context;
		this.myItems = items;
		this.myOnItemClickListener = onItemClickListener;
		this.myType = type;

		this.myWidth = width;
		this.myHeight = height;

		System.out.println("--myWidth--:" + myWidth + "--myHeight--:"
				+ myHeight);
		initWidget();
		setPopup();
	}

	/**
	 * 初始化控制元件
	 */
	private void initWidget() {
		myLv = (ListView) myMenuView.findViewById(R.id.popup_lv);
		popupLL = (LinearLayout) myMenuView.findViewById(R.id.popup_layout);
		myLv.setOnItemClickListener(myOnItemClickListener);

		if (myType == 1) {
			android.widget.RelativeLayout.LayoutParams lpPopup = (android.widget.RelativeLayout.LayoutParams) popupLL
					.getLayoutParams();
			lpPopup.width = (int) (myWidth * 1.0 / 4);
			lpPopup.setMargins(0, 0, (int) (myWidth * 3.0 / 4), 0);
			popupLL.setLayoutParams(lpPopup);
		} else if (myType == 2) {
			android.widget.RelativeLayout.LayoutParams lpPopup = (android.widget.RelativeLayout.LayoutParams) popupLL
					.getLayoutParams();
			lpPopup.width = (int) (myWidth * 1.0 / 4);
			lpPopup.setMargins((int) (myWidth * 3.0 / 4), 0, 0, 0);
			popupLL.setLayoutParams(lpPopup);
		}
	}

	/**
	 * 設定popup的樣式
	 */
	private void setPopup() {
		// 設定AccessoryPopup的view
		this.setContentView(myMenuView);
		// 設定AccessoryPopup彈出窗體的寬度
		this.setWidth(LayoutParams.MATCH_PARENT);
		// 設定AccessoryPopup彈出窗體的高度
		this.setHeight(LayoutParams.MATCH_PARENT);
		// 設定AccessoryPopup彈出窗體可點選
		this.setFocusable(true);
		// 設定AccessoryPopup彈出窗體的動畫效果
		if (myType == 1) {
			this.setAnimationStyle(R.style.AnimTopLeft);
		} else if (myType == 2) {
			this.setAnimationStyle(R.style.AnimTopRight);
		} else {
			//this.setAnimationStyle(R.style.AnimTop);
			this.setAnimationStyle(R.style.AnimTopMiddle);
		}
		// 例項化一個ColorDrawable顏色為半透明
		ColorDrawable dw = new ColorDrawable(0x33000000);
		// 設定SelectPicPopupWindow彈出窗體的背景
		this.setBackgroundDrawable(dw);

		myMenuView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				int height = popupLL.getBottom();
				int left = popupLL.getLeft();
				int right = popupLL.getRight();
				System.out.println("--popupLL.getBottom()--:"
						+ popupLL.getBottom());
				int y = (int) event.getY();
				int x = (int) event.getX();
				if (event.getAction() == MotionEvent.ACTION_UP) {
					if (y > height || x < left || x > right) {
						System.out.println("---點選位置在列表下方--");
						dismiss();
					}
				}
				return true;
			}
		});
	}

	/**
	 * 顯示彈窗介面
	 * 
	 * @param view
	 */
	public void show(View view) {
		if (myIsDirty) {
			myIsDirty = false;
			adapter = new PopupAdapter(myContext, myItems, myType);
			myLv.setAdapter(adapter);
		}

		showAsDropDown(view, 0, 0);
	}

}

4.自定義彈窗佈局 top_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/popup_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="#ffffff"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/popup_lv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@color/content_line"
            android:dividerHeight="0.5dp" >
        </ListView>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:background="@color/reserve_line" />
    </LinearLayout>

</RelativeLayout>

5.彈窗類表介面卡類 PopupAdapter
package com.popuptest;

import java.util.ArrayList;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

public class PopupAdapter extends BaseAdapter {
	private Context myContext;
	private LayoutInflater inflater;
	private ArrayList<String> myItems;
	private int myType;

	public PopupAdapter(Context context, ArrayList<String> items, int type) {
		this.myContext = context;
		this.myItems = items;
		this.myType = type;

		inflater = LayoutInflater.from(myContext);

	}

	@Override
	public int getCount() {
		return myItems.size();
	}

	@Override
	public String getItem(int position) {
		return myItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		PopupHolder holder = null;
		if (convertView == null) {
			holder = new PopupHolder();
			convertView = inflater.inflate(R.layout.top_popup_item, null);
			holder.itemNameTv = (TextView) convertView
					.findViewById(R.id.popup_tv);
			if (myType == 0) {
				holder.itemNameTv.setGravity(Gravity.CENTER);
			} else if (myType == 1) {
				holder.itemNameTv.setGravity(Gravity.LEFT);
			} else if (myType == 2) {
				holder.itemNameTv.setGravity(Gravity.RIGHT);
			}
			convertView.setTag(holder);
		} else {
			holder = (PopupHolder) convertView.getTag();
		}
		String itemName = getItem(position);
		holder.itemNameTv.setText(itemName);
		return convertView;
	}

	private class PopupHolder {
		TextView itemNameTv;
	}

}

6.子item佈局 top_popup_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:padding="10dp" >

    <TextView
        android:id="@+id/popup_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        style="@style/urm_tv"/>

</RelativeLayout>

7.主介面頂部佈局 urm_top.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#eeeeee" >

    <ImageButton
        android:id="@+id/urm_back_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:background="@null"
        android:contentDescription="@string/app_name"
        android:src="@drawable/back" />

    <LinearLayout
        android:id="@+id/urm_top_ll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/urm_top_tv"
            style="@style/main_tv_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="企業客戶" />

        <ImageView
            android:id="@+id/urm_top_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:background="@null"
            android:contentDescription="@string/app_name"
            android:src="@drawable/switch02" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/urm_top_right_rl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true" >

        <ImageButton
            android:id="@+id/urm_create_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:contentDescription="@string/app_name"
            android:src="@drawable/btn_add_2x" />

        <Button
            android:id="@+id/urm_confirm_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:gravity="center_vertical"
            android:padding="10dp"
            android:text="確定"
            android:textColor="@color/blue2"
            android:textSize="18sp"
            android:visibility="gone" />
    </RelativeLayout>

    <ImageButton
        android:id="@+id/urm_search_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@id/urm_top_right_rl"
        android:background="@null"
        android:contentDescription="@string/app_name"
        android:src="@drawable/search"
        android:visibility="gone" />

</RelativeLayout>

8.styles.xml檔案
<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    
    <style name="AnimTop" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/push_top_in</item>
        <item name="android:windowExitAnimation">@anim/push_top_out</item>
    </style>
    
     <style name="AnimTopRight" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/top_right_in</item>
        <item name="android:windowExitAnimation">@anim/top_right_out</item>
    </style>
    
     <style name="AnimTopLeft" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/top_left_in</item>
        <item name="android:windowExitAnimation">@anim/top_left_out</item>
    </style>
    
     <style name="AnimTopMiddle" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/top_middle_in</item>
        <item name="android:windowExitAnimation">@anim/top_middle_out</item>
    </style>
    
    <style name="main_tv_style">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">#000000</item>
    </style>

    <style name="urm_tv">
        <item name="android:textSize">18sp</item>
    </style>
</resources>

9.各種動畫效果

push_top_in.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 從螢幕上面進入 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="500"
        android:fromYDelta="-100%p"
        android:toYDelta="0" />

    <alpha
        android:duration="500"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>

push_top_out.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 從螢幕上面退出 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="500"
        android:fromYDelta="0"
        android:toYDelta="-100%p" />

    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

</set>

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

    <scale
        android:duration="500"
        android:fillAfter="false"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="0%"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>

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

    <scale
        android:duration="500"
        android:fillAfter="false"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="0%"
        android:pivotY="0%"
        android:toXScale="0.0"
        android:toYScale="0.0" />

</set>

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

    <scale
        android:duration="500"
        android:fillAfter="false"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="50%"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>

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

    <scale
        android:duration="500"
        android:fillAfter="false"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="50%"
        android:pivotY="0%"
        android:toXScale="0.0"
        android:toYScale="0.0" />

</set>

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

    <scale
        android:duration="500"
        android:fillAfter="false"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="100%"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>

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

    <scale
        android:duration="500"
        android:fillAfter="false"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="100%"
        android:pivotY="0%"
        android:toXScale="0.0"
        android:toYScale="0.0" />

</set>

執行專案即可搞定!

相關推薦

Android PopupWindow實現頂部選單

          本例項的自定義下拉選單主要是繼承PopupWindow類來實現的彈出窗體,各種佈局效果可以根據自己定義設計。彈出的動畫效果主要用到了translate、alpha、scale,具體實現步驟如下:          先上效果圖如下:左邊下拉選單、中間下拉選

android開發】使用PopupWindow實現頁面點選頂部選單

沒有太多花樣,也沒有很複雜的技術,就是簡單的PopupWindow的使用,可以實現點選彈出一個自定義的view,view裡可以隨便設計,常用的可以放一個listview。 demo中我只是一個點選展示,簡單的使用了fade in out的動畫效果,也沒有精美的圖片資源,

android利用PopupWindow實現點選工具欄選單

package com.example.dropdownmenu; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.os.Bu

Android popwindow和fragment結合 左側選單 切換介面

      延續上一篇文章Android 實現對話方塊圓角功能 ,在專案推進的過程當中,之前是已經用popwindow實現了點選按鈕,在按鈕下方彈出下拉選單,實現了類似微信右上角加好友的功能,有興趣的朋友,可以下載這個資源。迴歸主題,之前popwindow的使用,是固定在

Android實現底部Dialog(和PopWindow實現的效果一樣)

上菜,不,上圖:       相信上圖的效果,大家在android 裝置中經常碰到.有時候進行分享操作的時候-----要求從從底部自下而上彈出.上圖中的效果**既可以通過自定義Dialog實現也可以通過自定義PopWindow來實現.**關於popWindow

Android實現底部的Dialog

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

AndroidPopupWindow列表

1. 首先看看main.xml佈局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.

Android PopupWindow怎麼合理控制位置

說到PopupWindow,應該都會有種熟悉的感覺,使用起來也很簡單 // 一個自定義的佈局,作為顯示的內容 Context context = null;  // 真實環境中要賦值 int layoutId = 0;      // 佈局ID View conten

android選擇選單,單選,多選

選單選擇視窗: 選單多選視窗 選單單選視窗: [java] view plaincopyprint? import android.app.Activity; import android.app.AlertDialog; import android.c

EasyUI Combobox 單擊

轉一位仁兄: 該事件在$('window').on('load',function(){ $("panel.combo").click(function(){   if ($(this).prev().combobox("panel").is(":visible")) {

點選文字框框並賦值

實現下面效果  窗體:Form1: 一:窗體佈局:文字框一個或多個,下拉框一個,初始化隱藏,定義全域性變數 string click_value = ""; private void Form1_Load(object sender, EventArgs e) {

RepositoryItemComboBox獲得焦點

在dev中的gridcontrol中添加了一列RepositoryItemComboBox下拉框列,想要實現當RepositoryItemComboBox列獲得焦點的時候,自動彈出下拉框,今天研究了一天,終於有結果了,先上圖 主要思路實現如下 1.先讓滑鼠游標移到到Rep

Android頂部提示的兩種實現方式

先給大家上一張效果圖:越來越多的APP提示越來越花哨,有中間的,有頂部的,有底部的,滑動滑出的,淡入淡出的,今天就先給大家做一個簡單的頂部彈出提示效果其實這是一個很簡單的功能,做起來也並不複雜,我們先看使用Toast如何實現第一種:Toast實現佈局檔案layout_toas

Android重寫ScrollView實現頭部放大功能

效果圖: 自定義ScrollView: public class MyScrollView extends ScrollView { //----頭部收縮屬性-------- // 記錄首次按下位置 private float mFirstPositi

透明Activity底部,除去頂部黑線和系統狀態列

這幾天發現透明Activity從底部彈出的時候,在5.0以下的安卓版本中,在彈出的過程中,頂部會有一條黑線;而在5.0的安卓系統中,發現系統狀態列居然也隨著Activity從底部彈出來了,看著非常不美觀啊。 5.0以下的安卓系統: 5.0版本的安卓系統:

androidRecyclerView控件實現長按PopupMenu菜單功能

mage 有一個 手工 sim pat 創建 .get mco span 之前寫過一篇文章:android中實現簡單的聊天功能 現在是在之前功能的基礎上,添加一個長按聊天記錄,刪除對應聊天記錄的功能 RecyclerView控件,沒有對應的長按事件,我們需要自己手工添加

選單選單實現——PopupMenu

PopupMenu代表彈出式選單,它會在指定元件上彈出PopupMenu,預設情況下,PopupMenu會顯示在該元件的下方或上方。PopupMenu可增加多個選單項,並可為選單項增加子選單。 使用PopupMenu建立選單的步驟非常簡單,只要如下步驟即可。 呼叫new PopupMenu(Context c

Android 仿蘑菇街列表和瀑布流 (ScrollView+RelativeLayout實現

之前看到用線性佈局寫的瀑布流,覺得不大好,自己想了另外一種方案, (最近發現用 網頁實現瀑布流 再用WebView載入才能完美實現效果) 原理使用RelativeLayout任意定位位置  核心方法 private void addViewByMargins(Re

Snackbars頂部實現

需要多個類的幫助,有需要的直接下載程式碼 記住需要先匯入依賴包:compile ‘com.android.support:design:23.0.0’ 主要程式碼的幫助類 幫助類1 import java.lang.ref.WeakRefe

Android實現ListView阻尼式()效果

最近想模仿小米MIUI V5簡訊裡面的一個功能——私密簡訊,它的入口在簡訊列表,列表往下拉到1/3左右,我用Eclipse上的工具截了圖,包括該結構的佈局,如下圖: 從它的UI結構可以看出,用的是層疊結構,即將ListView和一個普通View(取名叫privateEn