android开发分享Android对话框宽度

我似乎无法控制对话框的宽度。 我有一个像这样简单的布局

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:theme="@android:style/Theme.Dialog"> <ScrollView android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/name_prompt_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/name_prompt" android:padding="10dip"/> <EditText android:id="@+id/name_inp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:lines="1" android:maxLines="1" android:maxLength="48" android:inputType="text" /> <TextView android:id="@+id/t1_prompt_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/t1_prompt" android:padding="10dip"/> <Spinner android:id="@+id/t1_inp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:lines="1" android:maxLines="1" android:maxLength="48" android:inputType="text" android:singleLine="true" android:layout_weight="1" android:entries= "@array/t1_allowed_values" /> </LinearLayout> </ScrollView> </LinearLayout> 

出于某种原因,对话框只有足够宽的文本input字段大约11个字符。 如何使对话框宽度填充屏幕?

    我有同样的问题。

    我使用下面的代码来使对话框fill_parent,它工作正常。

     public class SharePost extends Dialog { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.adaptor_contentsharepost); LayoutParams params = getWindow().getAttributes(); params.height = LayoutParams.FILL_PARENT; getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); } } 

    布局

     <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/dialogWidth" android:layout_width="match_parent" android:layout_height="match_parent"> contents here </LinearLayout> 

    我在用着:

     getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 

    在最上面的布局中设置最小宽度。

     android:minWidth="300dp" 

    例如:

     <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="https://schemas.android.com/apk/res/android" android:minWidth="300dp"> <!-- Put remaining contents here --> </LinearLayout> 

    正如Matthias指出的那样, 如何获得一个对话框样式的活动窗口来填充屏幕? UMAR的解决scheme工作,但只有在调用setContentView()之后设置窗口属性。

    尝试这个。 这个对我有用。

      dialog = new Dialog(Activity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.feedback_popup); dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; lp.gravity = Gravity.CENTER; dialog.getWindow().setAttributes(lp); 

    由于API 8 FILL_PARENT已被弃用。 改用MATCH_PARENT。

    以上就是android开发分享Android对话框宽度相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。

     params.height = LayoutParams.MATCH_PARENT; 

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/addevelopment/514260.html

      (0)
      上一篇 2020年11月30日
      下一篇 2020年11月30日

      精彩推荐