Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-通过编程更改弹出窗口';s布局_Android_Android Layout - Fatal编程技术网

Android-通过编程更改弹出窗口';s布局

Android-通过编程更改弹出窗口';s布局,android,android-layout,Android,Android Layout,我有一个PopupWindow,它最终决定遵循我的命令并在出现null错误后显示自己(当然不是我忘记初始化某个值的错误) 这是用于PopupWindow <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/popup_handphone_MainLayout"

我有一个
PopupWindow
,它最终决定遵循我的命令并在出现null错误后显示自己(当然不是我忘记初始化某个值的错误)

这是用于
PopupWindow

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_handphone_MainLayout"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/popup_handphone_Wrapper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/popupkodehp">

        <TextView
            android:id="@+id/popup_handphone_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:textColor="@color/textColor"
            android:text="@string/popupPhoneMessage"/>

        <RelativeLayout
            android:id="@+id/popup_handphone_functionalities"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/popup_handphone_text"
            android:layout_marginTop="15dp">

            <EditText
                android:id="@+id/popup_handphone_phoneNumber"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Phone Number"
                android:textColorHint="@color/textColor" />

            <EditText
                android:id="@+id/popup_handphone_phoneNumberConfirm"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/popup_handphone_phoneNumber"
                android:layout_marginTop="10dp"
                android:hint="Retype Phone Number"
                android:textColorHint="@color/textColor"/>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/popup_handphone_phoneNumberConfirm"
                android:layout_marginTop="20dp"
                android:minHeight="20dp"
                android:text="Send Code"
                android:textColor="@color/textColor"/>

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>
PopupWindow pw = new PopupWindow(
                    inflater.inflate(R.layout.popup_handphone, null, false),
                    (int)(width * .8),
                    (int)(height*.35),
                    true);
第二个注释部分是设置布局元素高度的失败尝试。它也显示在主布局上,如中所示,整个
PopupWindow
布局位于类布局的顶部


如何以编程方式自定义我从类“layout I'm at?”制作的
PopupWindow
布局

如果要在显示PopupWindow时更新
PopupWindow
宽度和高度,请使用函数
PopupWindow.update


希望这能有所帮助。

我找到了如何使用
PopupWindow.getContentView()更改
PopupWindow
内部的答案。

像往常一样,实例化
PopupWindow

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_handphone_MainLayout"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/popup_handphone_Wrapper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/popupkodehp">

        <TextView
            android:id="@+id/popup_handphone_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:textColor="@color/textColor"
            android:text="@string/popupPhoneMessage"/>

        <RelativeLayout
            android:id="@+id/popup_handphone_functionalities"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/popup_handphone_text"
            android:layout_marginTop="15dp">

            <EditText
                android:id="@+id/popup_handphone_phoneNumber"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Phone Number"
                android:textColorHint="@color/textColor" />

            <EditText
                android:id="@+id/popup_handphone_phoneNumberConfirm"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/popup_handphone_phoneNumber"
                android:layout_marginTop="10dp"
                android:hint="Retype Phone Number"
                android:textColorHint="@color/textColor"/>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/popup_handphone_phoneNumberConfirm"
                android:layout_marginTop="20dp"
                android:minHeight="20dp"
                android:text="Send Code"
                android:textColor="@color/textColor"/>

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>
PopupWindow pw = new PopupWindow(
                    inflater.inflate(R.layout.popup_handphone, null, false),
                    (int)(width * .8),
                    (int)(height*.35),
                    true);
然后使用调用
弹出窗口的布局

RelativeLayout popupFunctionalitiesWrapper = (RelativeLayout)pw.getContentView().findViewById(R.id.popup_handphone_functionalities);
请注意,
pw.getContentView()
位于
findViewById
之前

通过这个
popupFunctionatiesWrapper
,我可以设置像

int popupFunctionalitiesWrapperWidth = layoutResize.width(70);
            RelativeLayout.LayoutParams popupFunctionalitiesWrapperParams = (RelativeLayout.LayoutParams)popupFunctionalitiesWrapper.getLayoutParams();
            popupFunctionalitiesWrapperParams.width = popupFunctionalitiesWrapperWidth;
            popupFunctionalitiesWrapperParams.addRule(Gravity.CENTER);
            popupFunctionalitiesWrapper.setLayoutParams(popupFunctionalitiesWrapperParams);

是的,就是这样

那是给窗户的吗?或者它可以用于内部的单个组件??如果要重置
宽度
高度
然后
PopupWindow
对象,或者如果要更新内部的单个组件,则通过
PopupWindow.getContentView从PopupWindow获取视图,然后更新