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

alex001001001 2015-10-02 01:59:05
就是设置不了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();

}
}
...全文
227 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
alex001001001 2015-10-03
  • 打赏
  • 举报
回复
引用 1 楼 阿飞__的回复:
是导不了这个类?试一下自己手动导包吧
倒好了
alex001001001 2015-10-03
  • 打赏
  • 举报
回复
哪个类,你倒是给个详细点的解释呀
阿飞__ 2015-10-02
  • 打赏
  • 举报
回复
是导不了这个类?试一下自己手动导包吧
【SCI复现】基于纳什博弈的多微网主体电热双层共享策略研究(Matlab代码实现)内容概要:本文研究基于纳什博弈理论的多微网主体电热双层共享策略,通过构建双层优化模型实现多微网系统间的电能与热能协同调度与资源共享。上层模型以各微网主体为独立参与者,基于纳什博弈框架优化自身利益,下层模型则考虑能源耦合关系与网络约束,实现系统整体能效优化。研究采用Matlab进行代码实现与仿真验证,复现了SCI级别研究成果,涵盖模型构建、博弈均衡求解、能量共享机制设计等关键环节,有效提升了多微网系统的经济性与能源利用效率。; 适合人群:具备一定电力系统、博弈论及优化算法基础,从事能源互联网、微电网调度、综合能源系统等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于多微网系统中电热协同优化调度策略的设计与仿真;②支撑纳什博弈在能源共享场景中的建模与求解实践;③为综合能源系统中主体间利益协调与资源分配提供理论参考与代码实现范例; 阅读建议:建议结合Matlab代码深入理解双层模型的实现逻辑,重点关注博弈均衡的求解过程与收敛性分析,同时可拓展至其他多主体能源系统应用场景进行二次开发与验证。

80,479

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧