PoopubWindow,能用showAsDropDown,就是用不了showAtLocation,(如图)

alex001001001 alex001001001 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
就是设置不了Gravity,真是日了狗了,不知道是倒入类错了,还是其他其他原因


完整代码如下:
错的在倒数几行

package com.example.zhuwen.model_popubwindow;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.EditText;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class MainActivity extends Activity{

private PopupWindow popupWindow;
private View contentView;
private TextView tx_pop;
private TextView tx_test;
private EditText ed_test;
int width=0,height=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tx_pop = (TextView)findViewById(R.id.tx_pop);
tx_test = (TextView)findViewById(R.id.tx_test);
ed_test = (EditText)findViewById(R.id.ed_test);

//get the width and height of screen
final DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
width = metric.widthPixels/2;
height = metric.heightPixels/2;

tx_test.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Can Touch",
Toast.LENGTH_SHORT).show();
}
});

tx_pop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
get_pop();
}
});

}

public void get_pop() {

contentView = getLayoutInflater().inflate(R.layout.pop_win, null);
popupWindow = new PopupWindow(contentView, 300,
200);
popupWindow.setContentView(contentView);
//.setBackgroundDrawable(getResources().getDrawable(R.drawable.search_label_click));
//.setBackgroundColor(Color.parseColor("#F5F5DC"));
//.setBackgroundColor(Color.GRAY);
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.test));
//set "true" ,then you can enter something
//set "true",a popwin will disappear when you touch the outside of the popwin
popupWindow.setFocusable(true);
//decided the location of a popwin
popupWindow.showAtLocation(R.id.tx_pop,Gravity.LEFT, 0, 0);
//the command to close a popwin
//popupWindow.dismiss();

}
}
...全文

相关推荐

毕业设计含文档和代码VB商品配送中心库存仿真软件设计(源代码+论文)

毕业设计含文档和代码VB商品配送中心库存仿真软件设计(源代码+论文)

zz_ll9023

硕士复现燃料电池供氢系统建模及控制策略Simulink仿真(附带说明PPT+参考文献+复现模型+实物源码)

内容概要:本文围绕“【硕士复现】燃料电池供氢系统建模及控制策略Simulink仿真”这一科研资源包,系统介绍了燃料电池供氢系统的完整建模与控制策略仿真方案。资源包涵盖Simulink仿真模型、说明PPT、参考文献、复现模型及实物源码,重点实现了供氢系统的动态建模、压力与流量控制、氢气供给稳定性优化等核心功能,并采用先进的控制算法(如PID、MPC等)进行策略设计与验证。该资源注重理论与实践结合,完整呈现从系统建模、控制器设计到仿真调试的全流程,适用于新能源、氢能利用、电力电子与自动控制等领域的科研与工程应用。; 适合人群:具备一定MATLAB/Simulink操作基础,从事新能源、氢能技术、电力电子、自动化控制等方向的硕士研究生、科研人员及工程技术人员。; 使用场景及目标:①用于燃料电池供氢系统的教学演示与课程设计;②支撑科研项目中的系统建模与控制算法验证;③辅助毕业论文或学术论文的仿真部分复现与优化。; 阅读建议:建议使用者先阅读配套PPT和参考文献以建立理论基础,再结合Simulink模型逐步调试与修改参数,深入理解控制策略的设计思路与实现细节,鼓励在此基础上进行创新性改进与拓展研究。

荧光Matlab

科技中介服务机构如何通过平台提升服务效率与专业度?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

工博会资料工博会资料工博会资料122

工博会资料工博会资料工博会资料122

音符o

高校技术转移办公室人员如何提升成果转化项目的匹配效率?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN
评论 3
收藏 已收藏
分享
返回顶部
alex001001001
Android 80,489 成员 91,375 内容