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

Android仿泡泡窗實(shí)現(xiàn)下拉菜單條實(shí)例代碼

 更新時(shí)間:2017年05月03日 09:50:43   投稿:mrr  
最近參與android的項(xiàng)目開(kāi)發(fā),其中遇到這樣的需求:點(diǎn)擊下拉按鈕,顯示出所有的條目,有刪除和點(diǎn)擊功能,點(diǎn)擊后將條目顯示。下面通過(guò)實(shí)例代碼給大家介紹下Android仿泡泡窗實(shí)現(xiàn)下拉菜單條效果,需要的朋友參考下吧

功能描述:點(diǎn)擊下拉按鈕,顯示出所有的條目,有刪除和點(diǎn)擊功能,點(diǎn)擊后將條目顯示。

注意:泡泡窗默認(rèn)是沒(méi)有焦點(diǎn)的。要讓泡泡窗獲取到焦點(diǎn)。假如listview的item中有Button,ImageButton,CheckBox等會(huì)強(qiáng)制獲取焦點(diǎn)的view 此時(shí),listview的item無(wú)法獲取焦點(diǎn),從而無(wú)法被點(diǎn)擊 解決方法:給item的根布局增加以下屬性 Android:descendantFocusability="blocksDescendants"設(shè)置之后,Button獲取焦點(diǎn),item中其他控件也可以獲取焦點(diǎn),如果文本的文字過(guò)多,會(huì)被后面的圖標(biāo)蓋住,首先設(shè)置單行android:singleLine="true"再設(shè)置右邊距就蓋不住android:padding="40dp"

需要添加下面三項(xiàng)

//讓泡泡窗額度條目獲取到焦點(diǎn) 
    popupWindow.setFocusable(true); 
    //設(shè)置背景圖 
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); 
    popupWindow.setOutsideTouchable(true); 

主布局文件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="#22000000" 
  tools:context=".MainActivity" > 
  <RelativeLayout  
    android:layout_marginTop="40dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    > 
  <EditText 
    android:id="@+id/et" 
    android:singleLine="true" 
    android:padding="40dp" 
    android:layout_width="300dp" 
    android:layout_height="40dp" 
    /> 
  <ImageView  
    android:layout_width="wrap_content" 
    android:layout_height="40dp" 
    android:id="@+id/iv_select" 
    android:layout_centerVertical="true" 
    android:background="@drawable/ic_launcher" 
    android:layout_alignRight="@id/et" 
    /> 
  </RelativeLayout> 
</RelativeLayout> 

每一個(gè)條目的布局文件item_list.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:padding="5dp" 
  android:orientation="horizontal" > 
  <TextView  
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_launcher" 
    android:gravity="center_vertical" 
    android:drawablePadding="3dp" 
    android:text="123" 
    android:id="@+id/tv_number" 
    android:layout_weight="1" 
    /> 
  <ImageView  
    android:id="@+id/iv_delete" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/ic_launcher" 
    /> 
</LinearLayout> 

邏輯代碼MainActivity.java

package com.ldw.select; 
import java.util.ArrayList; 
import android.app.Activity; 
import android.graphics.drawable.BitmapDrawable; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.BaseAdapter; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.PopupWindow; 
import android.widget.TextView; 
public class MainActivity extends Activity implements OnClickListener{ 
  private ImageView iv_select; 
  private EditText et; 
  private ArrayList<String> list = new ArrayList<String>(); 
  private TextView tv_number; 
  private ImageView iv_delete; 
  private ListView listView; 
  private PopupWindow popupWindow; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    initView(); 
    initListener();  
    initData(); 
  } 
  private void initView() { 
    setContentView(R.layout.activity_main); 
    iv_select = (ImageView) findViewById(R.id.iv_select); 
    et = (EditText) findViewById(R.id.et); 
  } 
  private void initListener() { 
    iv_select.setOnClickListener(this); 
  } 
  //集合中添加數(shù)據(jù) 
  private void initData() { 
    for(int i = 0; i< 20; i++){ 
      list.add(1340000000 + i + ""); 
    } 
    initListView(); 
  } 
  //初始化列表 
  private void initListView(){ 
    listView = new ListView(this); 
    //設(shè)置listView的背景圖 
    listView.setBackgroundResource(R.drawable.ic_launcher); 
    //讓listView的滾動(dòng)條不可見(jiàn) 
    listView.setVerticalScrollBarEnabled(false); 
    MyAdapter adapter = new MyAdapter(); 
    listView.setAdapter(adapter); 
    listView.setOnItemClickListener(new OnItemClickListener(){ 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
          int position, long id) { 
        et.setText(list.get(position)); 
        //關(guān)閉泡泡窗 
        popupWindow.dismiss(); 
      } 
    }); 
  } 
  //泡泡窗實(shí)現(xiàn)點(diǎn)擊顯示列表,泡泡窗默認(rèn)是不獲取焦點(diǎn)的 
  private void showNumberList(){ 
    if(popupWindow == null){ 
    //泡泡窗的填充,設(shè)置寬高 
    popupWindow = new PopupWindow(listView, et.getWidth(), 300); 
    } 
    //讓泡泡窗額度條目獲取到焦點(diǎn) 
    popupWindow.setFocusable(true); 
    //設(shè)置背景圖 
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); 
    popupWindow.setOutsideTouchable(true); 
    //第一個(gè)參數(shù)是依附哪一個(gè)參數(shù)下,x軸,y軸的偏移量,相對(duì)于第一個(gè)參數(shù)的左下角的位置 
    popupWindow.showAsDropDown(et, 0, 0); 
  } 
  @Override 
  public void onClick(View v){ 
    switch (v.getId()){ 
      case R.id.iv_select: 
        //點(diǎn)擊彈出列表 
        showNumberList(); 
        break; 
    } 
  } 
  //listView填充 
  class MyAdapter extends BaseAdapter{ 
    @Override 
    public int getCount() { 
      return list.size(); 
    } 
    @Override 
    public Object getItem(int position) { 
      return null; 
    } 
    @Override 
    public long getItemId(int position) { 
      return 0; 
    } 
    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
      final View view = View.inflate(MainActivity.this, R.layout.item_list, null); 
      tv_number = (TextView) view.findViewById(R.id.tv_number); 
      iv_delete = (ImageView) view.findViewById(R.id.iv_delete); 
      tv_number.setText(list.get(position)); 
      //刪除按鍵 
      iv_delete.setOnClickListener(new OnClickListener(){ 
        @Override 
        public void onClick(View v) { 
          //刪除條目 
          list.remove(position); 
          //更新頁(yè)面 
          notifyDataSetChanged(); 
          //根據(jù)當(dāng)前條目的個(gè)數(shù)設(shè)置,當(dāng)前條目的高度 
          int listViewHeight = list.size() * view.getHeight(); 
          if(listViewHeight > 300){ 
            listViewHeight = 300; 
          }else{ 
            listViewHeight = listViewHeight; 
          } 
          //更新泡泡窗的高度 
          popupWindow.update(et.getWidth(), listViewHeight); 
          //刪除完了,泡泡窗小消失 
          if(list.size() == 0){ 
            popupWindow.dismiss(); 
            //下拉條消失 
            iv_select.setVisibility(View.GONE); 
          } 
        } 
      }); 
      return view; 
    } 
  } 
} 

以上所述是小編給大家介紹的Android仿泡泡窗實(shí)現(xiàn)下拉菜單條實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android菜單的定義及ActionBar的實(shí)現(xiàn)

    Android菜單的定義及ActionBar的實(shí)現(xiàn)

    本篇文章主要介紹了Android菜單的定義及ActionBar的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • Android使用gradle讀取并保存數(shù)據(jù)到BuildConfg流程詳解

    Android使用gradle讀取并保存數(shù)據(jù)到BuildConfg流程詳解

    這篇文章主要介紹了Android使用gradle從資源目錄讀取數(shù)據(jù)并存到BuildConfg內(nèi),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2023-02-02
  • Android開(kāi)發(fā)之Socket通信傳輸簡(jiǎn)單示例

    Android開(kāi)發(fā)之Socket通信傳輸簡(jiǎn)單示例

    這篇文章主要介紹了Android開(kāi)發(fā)之Socket通信傳輸實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android socket傳輸?shù)脑怼?shí)現(xiàn)方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2017-08-08
  • MaterialApp?Flutter?應(yīng)用全局配置與主題管理詳解

    MaterialApp?Flutter?應(yīng)用全局配置與主題管理詳解

    這篇文章主要為大家介紹了MaterialApp?Flutter?應(yīng)用全局配置與主題管理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • Android程序結(jié)構(gòu)簡(jiǎn)單講解

    Android程序結(jié)構(gòu)簡(jiǎn)單講解

    在本篇文章里小編給大家分享一篇關(guān)于Android程序結(jié)構(gòu)的簡(jiǎn)單說(shuō)明內(nèi)容,有需要的朋友們跟著學(xué)習(xí)下。
    2019-02-02
  • Android中activity處理返回結(jié)果的實(shí)現(xiàn)方式

    Android中activity處理返回結(jié)果的實(shí)現(xiàn)方式

    這篇文章主要介紹了Android中activity處理返回結(jié)果的實(shí)現(xiàn)方式,為了實(shí)現(xiàn)這個(gè)功能,Android提供了一個(gè)機(jī)制,跳轉(zhuǎn)到其他activity時(shí),再返回,可以接受到其他activity返回的值,無(wú)需再start新的當(dāng)前activity。需要的朋友可以參考下
    2016-12-12
  • Android?Flutter制作一個(gè)修改組件屬性的動(dòng)畫(huà)

    Android?Flutter制作一個(gè)修改組件屬性的動(dòng)畫(huà)

    flutter為我們提供了一個(gè)AnimationController來(lái)對(duì)動(dòng)畫(huà)進(jìn)行詳盡的控制,不過(guò)直接是用AnimationController是比較復(fù)雜的,如果只是對(duì)一個(gè)widget的屬性進(jìn)行修改,可以做成動(dòng)畫(huà)嗎,本文就來(lái)探討一下
    2023-05-05
  • 解決Android Studio XML編輯界面不顯示下面的Text和Design選項(xiàng)卡

    解決Android Studio XML編輯界面不顯示下面的Text和Design選項(xiàng)卡

    這篇文章主要介紹了解決Android Studio XML編輯界面不顯示下面的Text和Design選項(xiàng)卡,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • 在Android項(xiàng)目中使用AspectJ的方法

    在Android項(xiàng)目中使用AspectJ的方法

    這篇文章主要介紹了在Android項(xiàng)目中使用AspectJ的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • Android開(kāi)發(fā)之背景動(dòng)畫(huà)簡(jiǎn)單實(shí)現(xiàn)方法

    Android開(kāi)發(fā)之背景動(dòng)畫(huà)簡(jiǎn)單實(shí)現(xiàn)方法

    這篇文章主要介紹了Android開(kāi)發(fā)之背景動(dòng)畫(huà)簡(jiǎn)單實(shí)現(xiàn)方法,涉及Android背景動(dòng)畫(huà)簡(jiǎn)單設(shè)置與使用技巧,需要的朋友可以參考下
    2017-10-10

最新評(píng)論

滦平县| 惠来县| 龙门县| 牟定县| 丁青县| 大邑县| 临江市| 凤冈县| 竹山县| 巩留县| 鄄城县| 定边县| 澄江县| 冷水江市| 木兰县| 宁河县| 会同县| 湟源县| 乐昌市| 宕昌县| 绥芬河市| 区。| 辰溪县| 庆阳市| 张家口市| 合肥市| 扶绥县| 望谟县| 琼结县| 白水县| 海淀区| 瑞昌市| 鱼台县| 克拉玛依市| 乐安县| 南岸区| 德阳市| 自贡市| 监利县| 望奎县| 高台县|