java窗口自动弹出_java - 如何设置弹出窗口的屏幕自动适合水平屏幕的长度 - SO中文参考 - www.soinside.com...

我希望我的Pop up windown适合水平长度的各种尺寸的移动屏幕?这里是我的Java和XML代码:So On Button点击菜单2活动中出现的弹出窗口,我希望它与屏幕完全一致,垂直方向应该有1000的长度。

JAVA:

package amapps.impossiblequiz;

public class Menu2 extends AppCompatActivity {

private DrawerLayout mDrawerLayout2;

private ActionBarDrawerToggle mToggle;

private Toolbar mToolbar;

private Button popup;

private PopupWindow popupWindow;

private LayoutInflater layoutInflater;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_menu2);

TextView txtScore = (TextView) findViewById(R.id.textScore2);

TextView txtHighScore = (TextView)findViewById(R.id.textHighScore);

ImageView imgTrophyView1 = (ImageView)findViewById(R.id.trophy1);

ImageView imgTrophyView2 = (ImageView) findViewById(R.id.trophy2);

TextView trophy1Txt = (TextView) findViewById(R.id.trophy1Text);

TextView trophy2Txt = (TextView) findViewById(R.id.trophy2Text);

Intent intent = getIntent();

int mScore = intent.getIntExtra ("score",0);

txtScore.setText("Your score is: " + mScore);

SharedPreferences sharedpreferences = getSharedPreferences("mypref", Context.MODE_PRIVATE);

int applyView =sharedpreferences.getInt("currentscore",0);

SharedPreferences mypref =getPreferences(MODE_PRIVATE);

int highScore = mypref.getInt("highScore", 0);

if (highScore>= mScore)

txtHighScore.setText("High score: " + highScore);

else{

txtHighScore.setText("New highscore: " + mScore);

SharedPreferences.Editor editor = mypref.edit();

editor.putInt("highScore",mScore);

editor.commit();

}

if (applyView >=10) {

imgTrophyView1.setVisibility(View.VISIBLE);

trophy1Txt.setVisibility(View.VISIBLE);

}

if (applyView >= 20){

imgTrophyView2.setVisibility(View.VISIBLE);

trophy2Txt.setVisibility(View.VISIBLE);

}

popup = (Button)findViewById(R.id.enablePOPUP);

popup.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

layoutInflater =(LayoutInflater)

getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);

ViewGroup container =

(ViewGroup)layoutInflater.inflate(R.layout.popup_menu2_1,null);

popupWindow = new PopupWindow(container,1000,980,true);

popupWindow.showAtLocation(mDrawerLayout2,

Gravity.NO_GRAVITY,500,500);

container.setOnTouchListener(new View.OnTouchListener(){

@Override

public boolean onTouch(View view, MotionEvent

motionEvent){

popupWindow.dismiss();

return true;

}

});

}

});

mToolbar = (Toolbar)findViewById(R.id.nav_action);

setSupportActionBar(mToolbar);

mDrawerLayout2 = (DrawerLayout) findViewById(R.id.drawerLayout2);

mToggle = new ActionBarDrawerToggle(this, mDrawerLayout2, R.string.open, R.string.close);

mDrawerLayout2.addDrawerListener(mToggle);

mToggle.syncState();

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

NavigationView mNavigationView = (NavigationView) findViewById(nv2);

mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

@Override

public boolean onNavigationItemSelected(MenuItem menuItem){

switch (menuItem.getItemId()){

case(R.id.nav_home2):

Intent accountActivity2 = new Intent(getApplicationContext(),QuizActivity.class);

startActivity(accountActivity2);

}

return true;

}

});}

public void onClick(View view) {

Intent intent = new Intent(Menu2.this, QuizActivity.class);

startActivity(intent);

}

@Override //Makes that the "Burger" Item, shows the Drawer if someone clicks on the simbol

public boolean onOptionsItemSelected(MenuItem item) {

if (mToggle.onOptionsItemSelected(item)) {

return true;

}

return super.onOptionsItemSelected(item);

}

}

XML:

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#000"

android:alpha="0.95">

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/textView3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_centerVertical="true"

android:paddingLeft="50dp"

android:paddingRight="50dp"

android:text="You reached a score of 10, you have a basic

knowledge!"

android:textAlignment="center"

android:textAppearance="@style/TextAppearance.AppCompat.Button"

android:textColor="#ffffff"

android:textSize="20dp" />

android:layout_width="80dp"

android:layout_height="80dp"

android:src="@drawable/trophy1"

android:layout_marginTop="22dp"

android:layout_below="@+id/textView3"

android:layout_centerHorizontal="true" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值