最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android Menu半透明效果的開發(fā)實例

 更新時間:2016年09月14日 08:42:36   投稿:lqh  
這篇文章主要介紹了Android Menu半透明效果方法的相關(guān)資料,需要的朋友可以參考下

不知道大家是否用過天天動聽,對于它界面上的半透明Menu效果,筆者感覺非常漂亮。下面是天天動聽半透明Menu的截圖,欣賞下吧:

       感覺還不錯吧?那么如何實現(xiàn)這種半透明Menu效果呢?本文就重點討論并給出這種Menu的具體代碼實現(xiàn)過程。

       首先分析下實現(xiàn)這種半透明Menu所需做的工作,并進行合理分解:

       1.  利用Shaper設(shè)置一個半透明圓角背景。

       2.  定義Menu布局,主要就GridView,把圖標都放在這個GridView。

       3.  Menu事件, 通過PopupWindow或者AlertDialog或者透明Activity顯示到頁面即可。

       4.  按鈕的監(jiān)聽事件,實例中沒加。需要的話自己在Adapter里加。

       比較簡單,不多說了。

       半透明圓角背景xml:

XML/HTML代碼

<?xml version="1.0" encoding="UTF-8"?> 
 
<shape android:shape="rectangle">  
 
 <solid android:color="#b4000000" /> 
 
 <stroke android:width="2.0dip" android:color="#b4ffffff" android:dashWidth="3.0dip" android:dashGap="0.0dip" /> 
 
 <padding android:left="7.0dip" android:top="7.0dip" android:right="7.0dip" android:bottom="7.0dip" /> 
 
 <corners android:radius="8.0dip" /> 
 
</shape> 

        Menu布局:

XML/HTML代碼

<?xml version="1.0" encoding="UTF-8"?> 
 
<LinearLayout 
 
  android:orientation="vertical" 
 
  android:layout_width="wrap_content" 
 
  android:layout_height="fill_parent"> 
  
 
  <GridView android:gravity="center" 
 
    android:layout_gravity="center" 
 
    android:id="@+id/menuGridChange" 
    
    android:background="@drawable/menu_bg_frame" 
 
    android:padding="5.0dip" 
 
    android:layout_width="fill_parent" 
 
    android:layout_height="wrap_content" 
 
    android:horizontalSpacing="10.0dip" 
 
    android:verticalSpacing="3.0dip" 
 
    android:stretchMode="columnWidth" 
 
    android:columnWidth="60.0dip" 
 
    android:numColumns="auto_fit"/> 
 
     
</LinearLayout> 

       主要類:

Java代碼

package com.yfz; 
 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.AlertDialog.Builder; 
import android.content.Context; 
import android.graphics.drawable.BitmapDrawable; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.ContextMenu; 
import android.view.Gravity; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.ContextMenu.ContextMenuInfo; 
import android.widget.BaseAdapter; 
import android.widget.GridView; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.PopupWindow; 
import android.widget.TextView; 
import android.widget.LinearLayout.LayoutParams; 
 
public class MenuTest extends Activity {   
 
  private String TAG = this.getClass().getSimpleName();   
 
  private int[] resArray = new int[] { 
    R.drawable.icon_menu_addto, R.drawable.icon_menu_audioinfo, 
    R.drawable.icon_menu_findlrc, R.drawable.icon_menu_scan 
  };   
 
  private String[] title = new String[]{ 
    "添加歌曲", "歌曲信息", "查找歌詞", "搜索歌詞" 
  };   
 
  private static boolean show_flag = false;   
  private PopupWindow pw = null;   
 
  /** Called when the activity is first created. */ 
  @Override 
  public void onCreate(Bundle savedInstanceState) { 
   super.onCreate(savedInstanceState); 
   setContentView(R.layout.main); 
  } 
 
  @Override 
 
  public boolean onCreateOptionsMenu(Menu menu) { 
    Log.e(TAG, "------ onCreateOptionsMenu ------"); 
    //用AlertDialog彈出menu 
 
//    View view = LayoutInflater.from(this).inflate(R.layout.menu, null); 
 
//    GridView grid1 = (GridView)view.findViewById(R.id.menuGridChange); 
 
//    grid1.setAdapter(new ImageAdapter(this)); 
 
//    Builder build = new AlertDialog.Builder(this); 
 
//    build.setView(view); 
 
//    build.show(); 
     
    LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);   
 
    View view = inflater.inflate(R.layout.menu, null); 
 
    GridView grid1 = (GridView)view.findViewById(R.id.menuGridChange); 
 
    grid1.setAdapter(new ImageAdapter(this));     
 
    //用Popupwindow彈出menu 
    pw = new PopupWindow(view,LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);     
 
    //NND, 第一個參數(shù), 必須找個View 
    pw.showAtLocation(findViewById(R.id.tv), Gravity.CENTER, 0, 300);     
 
    return true; 
  } 
 
  @Override 
 
  public boolean onOptionsItemSelected(MenuItem item) { 
    return super.onOptionsItemSelected(item); 
  } 
 
  public class ImageAdapter extends BaseAdapter {     
    private Context context;     
 
    public ImageAdapter(Context context) { 
      this.context = context; 
    }     
 
    @Override 
    public int getCount() { 
      return resArray.length; 
    } 
 
    @Override 
    public Object getItem(int arg0) { 
      return resArray[arg0]; 
    } 
 
    @Override 
    public long getItemId(int arg0) { 
      return arg0; 
    } 
 
    @Override 
    public View getView(int arg0, View arg1, ViewGroup arg2) { 
      LinearLayout linear = new LinearLayout(context); 
 
      LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
 
      linear.setOrientation(LinearLayout.VERTICAL);       
 
      ImageView iv = new ImageView(context); 
 
      iv.setImageBitmap(((BitmapDrawable)context.getResources().getDrawable(resArray[arg0])).getBitmap()); 
 
      LinearLayout.LayoutParams params2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
 
      params2.gravity=Gravity.CENTER; 
 
      linear.addView(iv, params2);       
 
      TextView tv = new TextView(context); 
 
      tv.setText(title[arg0]); 
 
      LinearLayout.LayoutParams params3 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
 
      params3.gravity=Gravity.CENTER;       
 
      linear.addView(tv, params3);       
      return linear; 
    } 
  } 
} 

        到此,大家是不是覺得半透明Menu效果也是比較好實現(xiàn)的呢?可以根據(jù)自己的需要對此實例進行修改以求更美觀好用。

        以上就是對Android Menu 半透明效果的實現(xiàn),后續(xù)繼續(xù)補充相關(guān)資料謝謝大家對本站的支持!

相關(guān)文章

  • Android RecyclerView選擇多個item的實現(xiàn)代碼

    Android RecyclerView選擇多個item的實現(xiàn)代碼

    這篇文章主要為大家詳細介紹了Android RecyclerView選擇多個item的實現(xiàn)代碼,仿網(wǎng)易新聞客戶端頻道選擇效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android 自定義view實現(xiàn)水波紋動畫效果

    Android 自定義view實現(xiàn)水波紋動畫效果

    這篇文章主要介紹了 Android 自定義view實現(xiàn)水波紋動畫效果的實例代碼,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2017-01-01
  • 在Android里完美實現(xiàn)基站和WIFI定位

    在Android里完美實現(xiàn)基站和WIFI定位

    眾所周知的,在OPhone和大部分國產(chǎn)的Android定制機里不支持最簡單實用的基站和WIFI定位,只能使用速度慢而耗電的GPS定位,但OPhone和華為/中興生產(chǎn)的一些Android定制機卻占據(jù)了一定的市場,因此導(dǎo)致了很多使用了定位技術(shù)的Andorid應(yīng)用挺尷尬的。
    2014-07-07
  • Android中ImageView用法實例分析

    Android中ImageView用法實例分析

    這篇文章主要介紹了Android中ImageView用法,結(jié)合實例形式較為詳細的分析了ImageView控件的功能,屬性設(shè)置與使用相關(guān)技巧,需要的朋友可以參考下
    2016-02-02
  • Android Studio利用AChartEngine制作餅圖的方法

    Android Studio利用AChartEngine制作餅圖的方法

    閑來無事,發(fā)現(xiàn)市面上好多app都有餅圖統(tǒng)計的功能,得空自己實現(xiàn)一下,下面這篇文章主要給大家介紹了關(guān)于Android Studio利用AChartEngine制作餅圖的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧
    2018-10-10
  • Android媒體開發(fā)之音樂播放器

    Android媒體開發(fā)之音樂播放器

    這篇文章主要為大家詳細介紹了Android媒體開發(fā)之音樂播放器,播放SD卡中的音樂,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android短信驗證碼(用的Mob短信驗證)

    Android短信驗證碼(用的Mob短信驗證)

    這篇文章主要為大家詳細介紹了Android短信驗證碼,使用Mob短信驗證,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Android 新手入門體驗

    Android 新手入門體驗

    本篇文章小編為大家介紹,Android 新手入門體驗。需要的朋友參考下
    2013-04-04
  • Android實現(xiàn)指定時間定時觸發(fā)方法

    Android實現(xiàn)指定時間定時觸發(fā)方法

    這篇文章主要為大家詳細介紹了Android實現(xiàn)指定時間定時觸發(fā)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Android中ListView下拉刷新的實現(xiàn)代碼

    Android中ListView下拉刷新的實現(xiàn)代碼

    這篇文章主要介紹了Android中ListView下拉刷新的實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-06-06

最新評論

汉川市| 鄂托克前旗| 包头市| 义马市| 子长县| 佳木斯市| 全椒县| 囊谦县| 钟山县| 岳普湖县| 崇义县| 溆浦县| 九江市| 南皮县| 昌都县| 中山市| 明星| 丰宁| 轮台县| 惠州市| 五台县| 务川| 磐安县| 那坡县| 右玉县| 旌德县| 崇文区| 金沙县| 铜川市| 平江县| 镇坪县| 五大连池市| 额尔古纳市| 吴旗县| 简阳市| 玉门市| 刚察县| 轮台县| 西藏| 镇巴县| 特克斯县|