編輯:關於Android編程
/** 彈popwindow **/ tv = (TextView) findViewById(R.id.textView1); view_pop = LayoutInflater.from(MainActivity.this).inflate( R.layout.pop_menu, null); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (mPopupwinow == null) { //新建一個popwindow mPopupwinow = new PopupWindow(view_pop, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true); //設置popwindow的背景顏色 mPopupwinow.setBackgroundDrawable(new ColorDrawable( 0x00000000)); } //設置popwindow的位置 tv:為微信右上角+號view,居於+號下方 mPopupwinow.showAsDropDown(tv, 0, 0); } });布局pop_menu.xml:
/** 彈dialog **/ private void showDialog() { dialog = new Dialog(this,R.style.dialog); view_dialog = LayoutInflater.from(MainActivity.this).inflate( R.layout.dialog_layout, null); dialog.setContentView(view_dialog); TextView tv_cancle = (TextView) view_dialog .findViewById(R.id.tv_cancle); tv_cancle.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); /* * 獲取聖誕框的窗口對象及參數對象以修改對話框的布局設置, 可以直接調用getWindow(),表示獲得這個Activity的Window * 對象,這樣這可以以同樣的方式改變這個Activity的屬性. */ Window dialogWindow = dialog.getWindow(); //設置位置 dialogWindow.setGravity(Gravity.BOTTOM); //設置dialog的寬高屬性 dialogWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); dialog.show(); }
package com.yqy.yqy_popwindow; import android.app.Activity; import android.app.Dialog; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.PopupWindow; import android.widget.TextView; public class MainActivity extends Activity { private TextView tv; private View view_pop, view_dialog; private PopupWindow mPopupwinow = null; private Button btn_dialog; private Dialog dialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /** 彈popwindow **/ tv = (TextView) findViewById(R.id.textView1); view_pop = LayoutInflater.from(MainActivity.this).inflate( R.layout.pop_menu, null); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (mPopupwinow == null) { //新建一個popwindow mPopupwinow = new PopupWindow(view_pop, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true); //設置popwindow的背景顏色 mPopupwinow.setBackgroundDrawable(new ColorDrawable( 0x00000000)); } //設置popwindow的位置 tv:為微信右上角+號view,居於+號下方 mPopupwinow.showAsDropDown(tv, 0, 0); } }); btn_dialog = (Button) findViewById(R.id.button1); btn_dialog.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { showDialog(); } }); } /** 彈dialog **/ private void showDialog() { dialog = new Dialog(this,R.style.dialog); view_dialog = LayoutInflater.from(MainActivity.this).inflate( R.layout.dialog_layout, null); dialog.setContentView(view_dialog); TextView tv_cancle = (TextView) view_dialog .findViewById(R.id.tv_cancle); tv_cancle.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); /* * 獲取聖誕框的窗口對象及參數對象以修改對話框的布局設置, 可以直接調用getWindow(),表示獲得這個Activity的Window * 對象,這樣這可以以同樣的方式改變這個Activity的屬性. */ Window dialogWindow = dialog.getWindow(); //設置位置 dialogWindow.setGravity(Gravity.BOTTOM); //設置dialog的寬高屬性 dialogWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); dialog.show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
IN THIS DOCUMENTCreating an Activity 創建一個ActivityImplementing a user interface 實現用戶界面
本文實例講述了Android編程布局(Layout)之AbsoluteLayout用法。分享給大家供大家參考,具體如下:AbsoluteLayout,顧名思義,就是絕對位
轉載請注明出處:http://blog.csdn.net/zhaokaiqiang1992 本文主要介紹了當我們使用限定符修飾我們的資源文件夾,例如drawable-en
最新更新的Flyme6整體效果不錯,動畫效果增加了很多了,看了看flyme6的Viewpager指示器,覺得有點意思,就模仿寫了一下,整體效果如下: GradleJitP