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

Android用PopupWindow實現(xiàn)新浪微博的分組信息實例

 更新時間:2016年11月05日 10:12:39   作者:90worker  
PopupWindow可以實現(xiàn)浮層效果,而且可以自定義顯示位置,本篇文章主要介紹Android用PopupWindow實現(xiàn)新浪微博的分組信息,有需要的可以了解一下。

最近看到新浪微博頂部欄的微博分組效果很炫,從網(wǎng)上查了一些資料明白原來是用PopupWindow實現(xiàn)的,今天自己也寫了一個例子實現(xiàn)了這種效果,希望對大家有幫助。

PopupWindow就是彈出窗口的意思,類似windows下面的開始按鈕。PopupWindow可以實現(xiàn)浮層效果,而且可以自定義顯示位置,出現(xiàn)和退出時的動畫.

效果如下:

實現(xiàn)思路:

在一個PopupWindow里放一個ListView,從而來達(dá)到分組信息的實現(xiàn)!

具體主要實現(xiàn)代碼:
group_list.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:layout_margin="0.0px" 
  android:background="@drawable/group_bg" 
  android:orientation="vertical" 
  android:paddingLeft="0.0sp" 
  android:paddingRight="0.0sp" > 
 
  <TextView 
    android:id="@+id/groupAll" 
    style="@style/grouplist_item_textview" 
    android:layout_width="fill_parent" 
    android:layout_height="@dimen/group_item_height" 
    android:background="@drawable/grouplist_fixed_item_bg" 
    android:gravity="center" 
    android:text="全部" /> 
 
  <ImageView 
    android:id="@+id/iv_group_list_bg_divider" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="0.0px" 
    android:background="@drawable/group_divider" 
    android:padding="0.0px" /> 
 
  <ListView 
    android:id="@+id/lvGroup" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="0.0" 
    android:cacheColorHint="#00000000" 
    android:divider="@drawable/group_divider" 
    android:dividerHeight="2.0px" 
    android:drawSelectorOnTop="true" 
    android:fadingEdgeLength="0.0sp" 
    android:listSelector="@drawable/grouplist_item_bg" /> 
 
</LinearLayout> 

group_item_view.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="fill_parent" 
  android:layout_height="@dimen/group_item_height" 
  android:orientation="vertical" > 
 
  <TextView 
    android:id="@+id/groupItem" 
    style="@style/grouplist_item_textview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center" /> 
 
</LinearLayout> 

Activity中的代碼:

package com.jiahui.popwindow; 
 
import java.util.ArrayList; 
import java.util.List; 
 
import com.jiahui.adapter.GroupAdapter; 
 
import android.app.Activity; 
import android.content.Context; 
import android.graphics.drawable.BitmapDrawable; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.WindowManager; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.ListView; 
import android.widget.PopupWindow; 
import android.widget.TextView; 
import android.widget.Toast; 
 
public class PoupWindowDemoActivity extends Activity { 
 
  private PopupWindow popupWindow; 
 
  private ListView lv_group; 
 
  private View view; 
 
  private View top_title; 
 
  private TextView tvtitle; 
 
  private List<String> groups; 
 
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
 
    top_title = this.findViewById(R.id.top_title); 
 
    tvtitle = (TextView) top_title.findViewById(R.id.tvtitle); 
 
    tvtitle.setText("做一個低調(diào)的碼農(nóng)"); 
 
    tvtitle.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
      public void onClick(View v) { 
        showWindow(v); 
      } 
    }); 
 
  } 
 
  /** 
   * 顯示 
   * 
   * @param parent 
   */ 
  private void showWindow(View parent) { 
 
    if (popupWindow == null) { 
      LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
 
      view = layoutInflater.inflate(R.layout.group_list, null); 
 
      lv_group = (ListView) view.findViewById(R.id.lvGroup); 
      // 加載數(shù)據(jù) 
      groups = new ArrayList<String>(); 
      groups.add("我的微博"); 
      groups.add("好友"); 
      groups.add("親人"); 
      groups.add("陌生人"); 
 
      GroupAdapter groupAdapter = new GroupAdapter(this, groups); 
      lv_group.setAdapter(groupAdapter); 
      // 創(chuàng)建一個PopuWidow對象 
      popupWindow = new PopupWindow(view, 200, 250); 
    } 
 
    // 使其聚集 
    popupWindow.setFocusable(true); 
    // 設(shè)置允許在外點擊消失 
    popupWindow.setOutsideTouchable(true); 
 
    // 這個是為了點擊“返回Back”也能使其消失,并且并不會影響你的背景 
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); 
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); 
    // 顯示的位置為:屏幕的寬度的一半-PopupWindow的高度的一半 
    int xPos = windowManager.getDefaultDisplay().getWidth() / 2 
        - popupWindow.getWidth() / 2; 
 
    Log.i("coder", "windowManager.getDefaultDisplay().getWidth()/2:" 
        + windowManager.getDefaultDisplay().getWidth() / 2); 
    // 
    Log.i("coder", "popupWindow.getWidth()/2:" + popupWindow.getWidth() / 2); 
 
    Log.i("coder", "xPos:" + xPos); 
 
    popupWindow.showAsDropDown(parent, xPos, 0); 
 
    lv_group.setOnItemClickListener(new OnItemClickListener() { 
 
      @Override 
      public void onItemClick(AdapterView<?> adapterView, View view, 
          int position, long id) { 
 
        Toast.makeText(PoupWindowDemoActivity.this, 
            "groups.get(position)" + groups.get(position), 1000) 
            .show(); 
 
        if (popupWindow != null) { 
          popupWindow.dismiss(); 
        } 
      } 
    }); 
  } 
} 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android利用Xfermode剪裁圓角

    Android利用Xfermode剪裁圓角

    這篇文章主要為大家詳細(xì)介紹了Android利用Xfermode剪裁圓角,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 淺析Android圓形進(jìn)度條ProgressBar如何實現(xiàn)固定進(jìn)度

    淺析Android圓形進(jìn)度條ProgressBar如何實現(xiàn)固定進(jìn)度

    之前遇到一個問題,發(fā)現(xiàn)Android里的圓形進(jìn)度條無法固定一個進(jìn)度,所以這篇文章就來和大家探索一下圓形進(jìn)度條ProgressBar如何實現(xiàn)固定進(jìn)度,希望對大家有所幫助
    2024-03-03
  • Android實現(xiàn)雙擊TitleBar回頂部的功能示例代碼

    Android實現(xiàn)雙擊TitleBar回頂部的功能示例代碼

    一個簡單易用的導(dǎo)航欄TitleBar,可以輕松實現(xiàn)IOS導(dǎo)航欄的各種效果,下面這篇文章主要給大家介紹了關(guān)于Android如何實現(xiàn)雙擊TitleBar回頂部功能的相關(guān)資料,文中給出了詳細(xì)的示例代碼,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-09-09
  • Android布局技巧之創(chuàng)建可重用的UI組件

    Android布局技巧之創(chuàng)建可重用的UI組件

    這篇文章主要為大家詳細(xì)介紹了Android布局技巧之創(chuàng)建可重用的UI組件,文中提到了include標(biāo)簽的使用方法,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android調(diào)用系統(tǒng)自帶的分享功能實例代碼

    Android調(diào)用系統(tǒng)自帶的分享功能實例代碼

    本篇文章主要介紹了Android調(diào)用系統(tǒng)自帶的分享功能實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-04-04
  • Android 幀動畫使用詳情

    Android 幀動畫使用詳情

    這篇文章主要介紹本文介紹使用AnimationDrawable類來實現(xiàn)動畫效果,需要的朋友可以參考下文
    2021-08-08
  • Android中使用socket通信實現(xiàn)消息推送的方法詳解

    Android中使用socket通信實現(xiàn)消息推送的方法詳解

    這篇文章主要介紹了Android中使用socket通信實現(xiàn)消息推送的方法,文中舉了一個消息發(fā)送端和一個消息接收端以及服務(wù)器端的例子來說明原理并且展示了客戶端的實現(xiàn),需要的朋友可以參考下
    2016-04-04
  • Android Studio發(fā)布項目到Jcenter倉庫步驟(圖文)

    Android Studio發(fā)布項目到Jcenter倉庫步驟(圖文)

    這篇文章主要介紹了Android Studio發(fā)布項目到Jcenter倉庫步驟(圖文),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-10-10
  • Android textview 實現(xiàn)長按自由選擇復(fù)制功能的方法

    Android textview 實現(xiàn)長按自由選擇復(fù)制功能的方法

    下面小編就為大家?guī)硪黄狝ndroid textview 實現(xiàn)長按自由選擇復(fù)制功能的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Android SearchView搜索框組件的使用方法

    Android SearchView搜索框組件的使用方法

    這篇文章主要為大家詳細(xì)介紹了Android SearchView搜索框組件的使用方法,即時搜索提示功能的實現(xiàn),感興趣的小伙伴們可以參考一下
    2016-05-05

最新評論

醴陵市| 凤山市| 施秉县| 招远市| 琼中| 张家港市| 昌平区| 桐城市| 临桂县| 拉萨市| 平罗县| 永登县| 景宁| 通海县| 噶尔县| 刚察县| 台南县| 三河市| 墨江| 巧家县| 祁阳县| 驻马店市| 青岛市| 西丰县| 富蕴县| 县级市| 娱乐| 丹江口市| 罗田县| 青田县| 肥乡县| 广南县| 饶河县| 乌鲁木齐县| 西平县| 洮南市| 同仁县| 安图县| 澄城县| 望江县| 潜江市|