我在我的Activity中實現了彈出窗口。問題是我想要設置彈出窗口匹配屏幕大小的寬度,現在我在兩邊留下了空間。這是現在的樣子如何android彈出窗口匹配屏幕大小寬度
這裏是我的彈出代碼:
LayoutInflater inflater = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
View layout = inflater.inflate(R.layout.activity_pop_up, null);
ImageView baner3img = (ImageView) layout.findViewById(R.id.baner3img);
Picasso.with(MainActivity.this).load(hrefScroll.get(2))
.into(baner3img);
// create PopupWindow
pw = new PopupWindow(layout, ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.MATCH_PARENT,true);
ImageView close = (ImageView) layout.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
findViewById(R.id.relativeLayoutZaFragment).post(new Runnable() {
public void run() {
pw.dismiss();
}
});
}
});
findViewById(R.id.relativeLayoutZaFragment).post(new Runnable() {
public void run() {
pw.setWindowLayoutMode(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
pw.setHeight(1);
pw.setWidth(1);
pw.showAtLocation(findViewById(R.id.relativeLayoutZaFragment), Gravity.CENTER, 1, 1);
new Handler().postDelayed(new Runnable(){
public void run() {
pw.dismiss();
}
}, 5 *1000);
}
});
}
});
activity_pop_up.xml:
<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:id="@+id/popup"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.bolt.automagazin.PopUp">
<ImageView
android:id="@+id/baner3img"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:srcCompat="@drawable/autojedan" />
<ImageView
android:id="@+id/close"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/baner3img"
android:layout_marginEnd="15dp"
android:visibility="visible"
app:srcCompat="@drawable/closeee" />
</RelativeLayout>
現在彈出相同夢詩,芽我得到完全透明的窗口... –
改變你的相對佈局'android:layout_width =「wrap_content」'到'match_parent' ...並添加任何背景顏色 – rafsanahmad007
現在彈出相同的大小,全屏與背景顏色在它 –