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

Android組件popupwindow使用方法詳解

 更新時間:2016年11月25日 11:52:59   作者:青蓮居士  
這篇文章主要為大家詳細介紹了Android組件popupwindow使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

先看效果: 

現(xiàn)在很多的應用效果都需要做的炫些,像UC,以及天天靜聽,效果很炫的,源碼已經(jīng)對外開放了,有興趣的可以去研究下的 

上源碼

main.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="500dp"
 android:orientation="vertical" 
 android:background="@android :color/white"
 >

 <include android:id="@+id/top_title"
 
 layout="@layout/title_two_button"/>
 <Button 
 android:id="@+id/bb"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="button"
 />
</LinearLayout>

title_two_button.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" >

 <TextView
 android:id="@+id/tvtitle"
 android:layout_width="fill_parent"
 android:layout_height="45dip"
 android:background="@drawable/search_bg"
 android:gravity="center"
 android:text="天下第一"
 android:textColor="@color/black"
 android:textSize="25dip" />

 <Button
 android:id="@+id/btn_title_left"
 android:layout_width="49dip"
 android:layout_height="36dip"
 android:layout_gravity="center_vertical"
 android:background="@drawable/title_button"
 android:textColor="@color/white" />

 <Button
 android:id="@+id/btn_title_right"
 android:layout_width="49dip"
 android:layout_height="36dip"
 android:layout_gravity="right"
 android:layout_marginRight="2dip"
 android:layout_marginTop="4dip"
 android:background="@drawable/title_button2"
 android:textColor="@color/white" />

</FrameLayout>

group_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:paddingLeft="0.0sp" android:paddingRight="0.0sp" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="0.0px"
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:background="@drawable/group_bg">

 <ImageView 
 android:id="@+id/iv_group_list_bg_divider" 
 android:background="@drawable/group_divider" 
 android:padding="0.0px" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:layout_margin="0.0px" />
 <ListView 
 android:id="@+id/lvGroup" 
 android:fadingEdgeLength="0.0sp" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:listSelector="@drawable/grouplist_item_bg" 
 android:drawSelectorOnTop="true" 
 android:cacheColorHint="#00000000" 
 android:divider="@drawable/group_divider" 
 android:dividerHeight="2.0px" 
 android:layout_weight="0.0" />
</LinearLayout>

group_item.xml

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

好了,這些都是其中用到的布局文件,開始重頭戲

package jk.activity;

import java.util.ArrayList;
import java.util.List;

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;
 
 private Button button;
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 button = (Button)findViewById(R.id.bb);
 top_title = this.findViewById(R.id.top_title);

 tvtitle = (TextView) top_title.findViewById(R.id.tvtitle);

 tvtitle.setText("天下第一");

 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);
 // 設置允許在外點擊消失
 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();
 }
 }
 });
 }
}

在這里還需要用到adapter,用到較多一般有baseadapter,simpleadapter,baseadapter挺強大的,不過simpleadapter擴展性挺不錯的,可以滿足自定義的需求,如果你理解輸入輸出流很快就能理解adapter的,他就是裝備數(shù)據(jù)的

package jk.activity;

import java.util.List;



import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class GroupAdapter extends BaseAdapter {

 private Context context;

 private List<String> list;

 public GroupAdapter(Context context, List<String> list) {

 this.context = context;
 this.list = list;

 }

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

 @Override
 public Object getItem(int position) {

 return list.get(position);
 }

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

 @Override
 public View getView(int position, View convertView, ViewGroup viewGroup) {

 
 ViewHolder holder;
 if (convertView==null) {
 convertView=LayoutInflater.from(context).inflate(R.layout.group_item_view, null);
 holder=new ViewHolder();
 
 convertView.setTag(holder);
 
 holder.groupItem=(TextView) convertView.findViewById(R.id.groupItem);
 
 }
 else{
 holder=(ViewHolder) convertView.getTag();
 }
 holder.groupItem.setText(list.get(position));
 
 return convertView;
 }

 static class ViewHolder {
 TextView groupItem;
 }

}

對于adapter,最重要是getView(int position, View convertView, ViewGroup viewGroup)這個方法的,菜已上完,各位慢慢享用。

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

相關(guān)文章

  • Android仿京東快報信息滾動效果

    Android仿京東快報信息滾動效果

    這篇文章主要為大家詳細介紹了Android仿京東快報信息滾動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • Android Animation實戰(zhàn)之屏幕底部彈出PopupWindow

    Android Animation實戰(zhàn)之屏幕底部彈出PopupWindow

    這篇文章主要為大家介紹了Android Animation動畫實戰(zhàn)項目,屏幕底部彈出PopupWindow,如何實現(xiàn)?文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-01-01
  • 解決Android studio3.6安裝后gradle Download失敗(構(gòu)建不成功)

    解決Android studio3.6安裝后gradle Download失敗(構(gòu)建不成功)

    這篇文章主要介紹了解決Android studio3.6安裝后gradle Download失敗(構(gòu)建不成功),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-03-03
  • Android實現(xiàn)動畫效果詳解

    Android實現(xiàn)動畫效果詳解

    這篇文章主要介紹了Android實現(xiàn)動畫效果詳解,目前Android平臺提供了Tween動畫和Frame動畫,實現(xiàn)這兩類動畫有兩種方式:一種使用XML文件(文件放在res/anim),一種直接代碼搞定,需要的朋友可以參考下
    2015-07-07
  • Android開發(fā)中ListView自定義adapter的封裝

    Android開發(fā)中ListView自定義adapter的封裝

    這篇文章主要為大家詳細介紹了android開發(fā)中ListView自定義adapter的封裝,ListView的模板寫法,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 5分鐘學會Android設計模式之策略模式Strategy Pattern教程

    5分鐘學會Android設計模式之策略模式Strategy Pattern教程

    這篇文章主要為大家介紹了5分鐘學會Android設計模式之策略模式Strategy Pattern教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • 實現(xiàn)輪轉(zhuǎn)廣告帶底部指示的自定義ViewPager控件

    實現(xiàn)輪轉(zhuǎn)廣告帶底部指示的自定義ViewPager控件

    在項目中經(jīng)常需要使用輪轉(zhuǎn)廣告的效果,在android-v4版本中提供的ViewPager是一個很好的工具,而一般我們使用Viewpager的時候,都會選擇在底部有一排指示物指示當前顯示的是哪一個page,下面我們就做這個功能的實現(xiàn)
    2013-11-11
  • Android中src和background的區(qū)別詳解

    Android中src和background的區(qū)別詳解

    這篇文章主要介紹了Android中src和background的區(qū)別詳解的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • Android Navigation TabBar控件實現(xiàn)多彩標簽欄

    Android Navigation TabBar控件實現(xiàn)多彩標簽欄

    這篇文章主要為大家詳細介紹了Android Navigation TabBar控件實現(xiàn)多彩標簽欄的相關(guān)代碼,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android自定義View詳解

    Android自定義View詳解

    這篇文章主要為大家詳細介紹了Android自定義View,幫助大家戰(zhàn)勝Android自定義View,為今后的學習打下基礎(chǔ),感興趣的小伙伴們可以參考一下
    2016-06-06

最新評論

石门县| 屏边| 桓仁| 高阳县| 酒泉市| 蓬安县| 驻马店市| 濉溪县| 泸西县| 休宁县| 通渭县| 汪清县| 郓城县| 巴塘县| 南华县| 岳普湖县| 嫩江县| 岳阳县| 平安县| 墨玉县| 砚山县| 华坪县| 永平县| 聂拉木县| 新津县| 鸡泽县| 温泉县| 吴堡县| 岑巩县| 遵义县| 卫辉市| 邵东县| 金寨县| 民丰县| 苍溪县| 遂川县| 怀柔区| 新野县| 马鞍山市| 大港区| 南充市|