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

Android實(shí)現(xiàn)點(diǎn)擊某個(gè)按鈕指定位置彈出布局

 更新時(shí)間:2020年12月16日 11:26:57   作者:小小龍2  
這篇文章主要介紹了Android實(shí)現(xiàn)點(diǎn)擊某個(gè)按鈕指定位置彈出布局,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)點(diǎn)擊某個(gè)按鈕指定位置彈出布局,供大家參考,具體內(nèi)容如下

package com.topcee.report.report;
 
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
 
import com.topcee.report.R;
 
import java.util.ArrayList;
import java.util.List;
 
public class HomeActivity extends Activity {
 private Context context;
 private List<String> reportList;
 private List<String> productList;
 private TextView tvReport;
 private TextView tvProduct;
 private TextView tvCompany;
 private String reportName = "";
 private String productName = "";
 private String companyName = "";
 private ListView lvData;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_home);
  context = HomeActivity.this;
  initView();
 }
 private void initView(){
  lvData = findViewById(R.id.lv_data);
  lvData.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 
   }
  });
  tvReport = findViewById(R.id.tv_report);
  tvProduct = findViewById(R.id.tv_product);
  tvCompany = findViewById(R.id.tv_company);
  tvReport.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    showReportDialog();
   }
  });
  tvProduct.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    showProductDialog();
   }
  });
  tvCompany.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    
   }
  });
 }
 
 /**
  * 報(bào)表彈窗
  */
 private void showReportDialog(){
  reportList = new ArrayList<>();
  reportList.add("生產(chǎn)報(bào)表");
  reportList.add("設(shè)備報(bào)表");
  reportList.add("拋料率報(bào)表");
  reportList.add("在線(xiàn)預(yù)警報(bào)表");
  View view = LayoutInflater.from(context).inflate(R.layout.popupwindow, null);
 
  // 為了演示效果,簡(jiǎn)單的設(shè)置了一些數(shù)據(jù),實(shí)際中大家自己設(shè)置數(shù)據(jù)即可,相信大家都會(huì)。
  ListView lsvMore = (ListView) view.findViewById(R.id.lsvMore);
  lsvMore.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, reportList));
 
  // 創(chuàng)建PopupWindow對(duì)象,指定寬度和高度
  PopupWindow window = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
  window.setWidth(tvReport.getWidth());
  // 設(shè)置動(dòng)畫(huà)
//  window.setAnimationStyle(R.style.popup_window_anim);
  // 設(shè)置背景顏色
  window.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
  // 設(shè)置可以獲取焦點(diǎn)
  window.setFocusable(true);
  // 設(shè)置可以觸摸彈出框以外的區(qū)域
  window.setOutsideTouchable(true);
  // 更新popupwindow的狀態(tài)
  window.update();
  // 以下拉的方式顯示,并且可以設(shè)置顯示的位置
//  window.showAsDropDown(tvReport, 0, 20);
  window.showAtLocation(tvReport, Gravity.LEFT | Gravity.BOTTOM, 0, 50);//這里的50是因?yàn)槲业撞堪粹o的高度是50
  lsvMore.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if("生產(chǎn)報(bào)表".equals(reportName)){
 
    }
   }
  });
 }
 
 /**
  * 生產(chǎn)情況彈窗
  */
 private void showProductDialog(){
  productList = new ArrayList<>();
  productList.add("生產(chǎn)描述");
  productList.add("生產(chǎn)進(jìn)度");
  productList.add("生產(chǎn)指標(biāo)");
  productList.add("異常信息");
  View view = LayoutInflater.from(context).inflate(R.layout.popupwindow, null);
 
  // 為了演示效果,簡(jiǎn)單的設(shè)置了一些數(shù)據(jù),實(shí)際中大家自己設(shè)置數(shù)據(jù)即可,相信大家都會(huì)。
  ListView lsvMore = view.findViewById(R.id.lsvMore);
  lsvMore.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, productList));
 
  // 創(chuàng)建PopupWindow對(duì)象,指定寬度和高度
  PopupWindow window = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
  window.setWidth(tvProduct.getWidth());
  // 設(shè)置動(dòng)畫(huà)
//  window.setAnimationStyle(R.style.popup_window_anim);
  // 設(shè)置背景顏色
  window.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
  // 設(shè)置可以獲取焦點(diǎn)
  window.setFocusable(true);
  // 設(shè)置可以觸摸彈出框以外的區(qū)域
  window.setOutsideTouchable(true);
  // 更新popupwindow的狀態(tài)
  window.update();
  // 以下拉的方式顯示,并且可以設(shè)置顯示的位置
//  window.showAsDropDown(tvProduct, 0, 20);
  window.showAtLocation(tvProduct, Gravity.CENTER | Gravity.BOTTOM, 0, 50);
  lsvMore.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    productName = productList.get(position);//獲取點(diǎn)擊的狀態(tài)名字
 
   }
  });
 }
}

activity_home.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".report.HomeActivity">
 <LinearLayout
  android:id="@+id/ll_list"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_above="@+id/activity_home_btn_layout">
  <ListView
   android:id="@+id/lv_data"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:divider="@null">
  </ListView>
 </LinearLayout>
 
 <View
  android:id="@+id/activity_home_bottom_line_layout"
  android:layout_above="@+id/activity_home_btn_layout"
  style="@style/style_row_line_view"/>
 <LinearLayout
  android:id="@+id/activity_home_btn_layout"
  android:layout_width="match_parent"
  android:layout_height="50dp"
  android:layout_alignParentBottom="true">
  <TextView
   android:id="@+id/tv_report"
   style="@style/style_activity_home_text_view"
   android:layout_weight="1"
   android:clickable="true"
   android:background="@drawable/btn_pressed"
   android:text="報(bào)表"/>
  <!--<ImageView
   android:layout_width="25dp"
   android:layout_height="match_parent"
   android:layout_gravity="center"
   android:layout_marginRight="5dp"
   android:layout_marginBottom="3dp"
   android:clickable="true"
   android:background="@drawable/btn_pressed"/>-->
  <View style="@style/style_column_line_view"/>
  <TextView
   android:id="@+id/tv_product"
   style="@style/style_activity_home_text_view"
   android:layout_weight="1"
   android:clickable="true"
   android:background="@drawable/btn_pressed"
   android:text="生產(chǎn)情況"/>
  <!--<ImageView
   android:layout_width="25dp"
   android:layout_height="match_parent"
   android:layout_gravity="center"
   android:layout_marginRight="5dp"
   android:layout_marginBottom="3dp"
   android:clickable="true"
   android:background="@drawable/btn_pressed"/>-->
  <View style="@style/style_column_line_view"/>
  <TextView
   android:id="@+id/tv_company"
   style="@style/style_activity_home_text_view"
   android:layout_weight="1"
   android:text="關(guān)于"
   android:clickable="true"
   android:background="@drawable/btn_pressed"/>
  <!--<ImageView
   android:layout_width="25dp"
   android:layout_height="match_parent"
   android:layout_gravity="center"
   android:layout_marginRight="5dp"
   android:layout_marginBottom="3dp"
   android:clickable="true"
   android:background="@drawable/btn_pressed"/>-->
 </LinearLayout>
 
</RelativeLayout>

btn_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@drawable/triangle_bg_pressed" android:state_pressed="true"></item>
 <item android:drawable="@drawable/triangle_bg"></item>
</selector>

triangle_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:id="@+id/shape"
  android:left="-2dp"
  android:bottom="-2dp">
  <!-- 長(zhǎng)方形 -->
  <shape android:shape="rectangle">
   <stroke android:color="#DFDFDF" android:width="1dp"/>
   <solid android:color="#DFDFDF"></solid>
  </shape>
 </item>
 <item android:id="@+id/shape_id">
  <!-- 正三角 -->
  <rotate
   android:fromDegrees="50"
   android:toDegrees="-50"
   android:pivotX="-50%"
   android:pivotY="100%">
   <shape android:shape="rectangle">
    <solid android:color="#DFDFDF"/>
   </shape>
  </rotate>
 </item>
</layer-list>

triangle_bg_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:id="@+id/shape"
  android:left="-2dp"
  android:bottom="-2dp">
  <!-- 長(zhǎng)方形 -->
  <shape android:shape="rectangle">
   <stroke android:color="#DFDFDF" android:width="1dp"/>
   <solid android:color="#DFDFDF"></solid>
  </shape>
 </item>
 <item android:id="@+id/shape_id">
  <!-- 正三角 -->
  <rotate
   android:fromDegrees="50"
   android:toDegrees="-50"
   android:pivotX="-50%"
   android:pivotY="100%">
   <shape android:shape="rectangle">
    <solid android:color="#DFDFDF"/>
   </shape>
  </rotate>
 </item>
</layer-list>

這里本來(lái)是想在右下角顯示一個(gè)小三角形的,不知道為啥不顯示,給它單獨(dú)拿出來(lái)設(shè)置寬度和高度就顯示。希望有知道的給我解惑一下。大家知識(shí)共享。

popupwindow.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:background="@drawable/popupwindow_bg">
 
 <ListView
  android:id="@+id/lsvMore"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
</LinearLayout>

這是最終的效果。

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

相關(guān)文章

  • Android 實(shí)現(xiàn)仿QQ拖拽氣泡效果的示例

    Android 實(shí)現(xiàn)仿QQ拖拽氣泡效果的示例

    這篇文章主要介紹了Android 實(shí)現(xiàn)仿QQ拖拽氣泡效果的示例,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-04-04
  • 詳解Android代碼混淆實(shí)戰(zhàn)

    詳解Android代碼混淆實(shí)戰(zhàn)

    這篇文章主要介紹了詳解Android代碼混淆實(shí)戰(zhàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Kotlin Option與Either及Result實(shí)現(xiàn)異常處理詳解

    Kotlin Option與Either及Result實(shí)現(xiàn)異常處理詳解

    Kotlin異常處理,異常是在程序運(yùn)行時(shí)可能發(fā)生的不必要的問(wèn)題,并突然終止您的程序。異常處理是一個(gè)過(guò)程,使用它可以防止程序出現(xiàn)可能破壞我們代碼的異常
    2022-12-12
  • Android實(shí)現(xiàn)閃屏歡迎界面

    Android實(shí)現(xiàn)閃屏歡迎界面

    這篇文章主要介紹了Android實(shí)現(xiàn)閃屏歡迎界面的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • android 網(wǎng)絡(luò)請(qǐng)求庫(kù)volley方法詳解

    android 網(wǎng)絡(luò)請(qǐng)求庫(kù)volley方法詳解

    這篇文章主要介紹了android 網(wǎng)絡(luò)請(qǐng)求庫(kù)volley方法詳解的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • Android中的緩存與文件存儲(chǔ)目錄詳解

    Android中的緩存與文件存儲(chǔ)目錄詳解

    在Android應(yīng)用開(kāi)發(fā)中,合理管理應(yīng)用的數(shù)據(jù)存儲(chǔ)至關(guān)重要,本文將詳細(xì)介紹cacheDir, filesDir, externalCacheDir, 以及getExternalFilesDir(Environment.DIRECTORY_PICTURES)這幾個(gè)目錄的用途和區(qū)別,感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • Kotlin中的高階函數(shù)深入講解

    Kotlin中的高階函數(shù)深入講解

    這篇文章主要給大家介紹了關(guān)于Kotlin中高階函數(shù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • Android Studio設(shè)置主題與字體大小圖文教程

    Android Studio設(shè)置主題與字體大小圖文教程

    這篇文章通過(guò)圖文詳細(xì)的給大家介紹了Android Studio中如何設(shè)置主題與字體大小,文章介紹的非常詳細(xì),相信對(duì)大家學(xué)習(xí)使用Android Studio具有一定的參考借鑒價(jià)值,有需要的朋友們下面來(lái)一起看看吧。
    2016-10-10
  • Android控件之菜單的創(chuàng)建方式

    Android控件之菜單的創(chuàng)建方式

    本文給大家分享android控件菜單的兩種創(chuàng)建方式,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-09-09
  • Android基于ViewPager實(shí)現(xiàn)類(lèi)似微信頁(yè)面切換效果

    Android基于ViewPager實(shí)現(xiàn)類(lèi)似微信頁(yè)面切換效果

    這篇文章主要介紹了Android基于ViewPager實(shí)現(xiàn)類(lèi)似微信頁(yè)面切換效果,通過(guò)Fragment適配器實(shí)現(xiàn)頁(yè)面切換效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05

最新評(píng)論

郓城县| 福安市| 益阳市| 蒙自县| 莎车县| 拉萨市| 肥西县| 即墨市| 吉木乃县| 富宁县| 金昌市| 仲巴县| 通渭县| 西盟| 康平县| 五常市| 浑源县| 容城县| 周宁县| 贡嘎县| 大同市| 白山市| 宁乡县| 延吉市| 沂水县| 秦皇岛市| 沙洋县| 南雄市| 彭水| 崇义县| 普格县| 虞城县| 五河县| 颍上县| 平南县| 西平县| 道真| 弋阳县| 达拉特旗| 新泰市| 平塘县|