У меня есть всплывающее окно с настраиваемым макетом, содержащим список элементов файла. Я хочу установить высоту для всплывающего окна на основе высоты настраиваемого макета. Я попыталсяне может получить точную высоту для линейного макета
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fileName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#303030"
android:orientation="vertical" >
<TextView
android:id="@+id/newfile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="first item"
android:textColor="@color/white"
android:drawableLeft="@drawable/zw_new"
android:drawablePadding="5dp"
android:padding="10dp"
android:textSize="20sp" />
<View style="@style/hrView" />
<TextView
android:id="@+id/rename"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="second item"
android:textColor="@color/white"
android:drawableLeft="@drawable/zw_rename"
android:drawablePadding="5dp"
android:padding="10dp"
android:textSize="20sp" />
</LinearLayout>
style.xml
<style name="hrView">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">#4f4f4f</item>
</style>
Код:
public static PopupWindow fileMenu= null;
public void showfileMenu(){
View fileMenuView=null;
fileMenuView = getLayoutInflater().inflate (R.layout.zw_filemenu, null);
fileMenuView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int h = fileMenuView.getMeasuredHeight();
int w = fileMenuView.getMeasuredWidth();
fileMenu=showPopup(fileMenuView,w,h);
}
PopupWindow pw=null;
public PopupWindow showPopup(View view,int w,int h) {
pw = new PopupWindow(EditorActivity.getActivity());
pw.setWidth(w);
pw.setHeight(h);
pw.setTouchable(true);
pw.setFocusable(true);
pw.setOutsideTouchable(true);
pw.setTouchInterceptor(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
pw.dismiss();
return true;
}
return false;
}
});
pw.setOutsideTouchable(false);
pw.setContentView(view);
return pw;
}
Я получаю высоту, 106 и ширину, 191. В связи с этим, мой всплывающее окно отображает только первый текстовый вид «первый элемент» (который слишком сломан), а второй элемент скрыт из-за меньшей высоты. Пожалуйста, помогите мне.
Это показывает всплывающее окно с полной ширины экрана. Я хочу показать его в верхней части определенного макета – vignesh
здесь измените mpopup.showAtLocation (popUpView, Gravity.BOTTOM, 0, 0); –