<legend id='IppuX'><style id='IppuX'><dir id='IppuX'><q id='IppuX'></q></dir></style></legend>
  • <small id='IppuX'></small><noframes id='IppuX'>

      <bdo id='IppuX'></bdo><ul id='IppuX'></ul>

    <tfoot id='IppuX'></tfoot>
  • <i id='IppuX'><tr id='IppuX'><dt id='IppuX'><q id='IppuX'><span id='IppuX'><b id='IppuX'><form id='IppuX'><ins id='IppuX'></ins><ul id='IppuX'></ul><sub id='IppuX'></sub></form><legend id='IppuX'></legend><bdo id='IppuX'><pre id='IppuX'><center id='IppuX'></center></pre></bdo></b><th id='IppuX'></th></span></q></dt></tr></i><div id='IppuX'><tfoot id='IppuX'></tfoot><dl id='IppuX'><fieldset id='IppuX'></fieldset></dl></div>

      1. 在 Android 中创建自定义对话框

        时间:2023-08-30
          <bdo id='cAMOe'></bdo><ul id='cAMOe'></ul>
            • <small id='cAMOe'></small><noframes id='cAMOe'>

                <tbody id='cAMOe'></tbody>
              <i id='cAMOe'><tr id='cAMOe'><dt id='cAMOe'><q id='cAMOe'><span id='cAMOe'><b id='cAMOe'><form id='cAMOe'><ins id='cAMOe'></ins><ul id='cAMOe'></ul><sub id='cAMOe'></sub></form><legend id='cAMOe'></legend><bdo id='cAMOe'><pre id='cAMOe'><center id='cAMOe'></center></pre></bdo></b><th id='cAMOe'></th></span></q></dt></tr></i><div id='cAMOe'><tfoot id='cAMOe'></tfoot><dl id='cAMOe'><fieldset id='cAMOe'></fieldset></dl></div>

                <tfoot id='cAMOe'></tfoot>

                <legend id='cAMOe'><style id='cAMOe'><dir id='cAMOe'><q id='cAMOe'></q></dir></style></legend>
                • 本文介绍了在 Android 中创建自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试在 Android 中创建自定义对话框.但是无论我尝试做什么,我都无法更改对话框的宽度.它只是保持不变.以下是我设置为对话框内容的视图.

                  I am trying to create a custom dialog in Android. But whatever I tried to do, I am not able to change the width of the dialog. It just remains the same. The following is the view that I am setting as the content for the dialog.

                  <RelativeLayout  
                  android:id="@+id/current_stats"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" 
                  android:visibility="visible">
                  <ImageView android:id="@+id/player_image" 
                      android:src="@drawable/person"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerHorizontal="true"/>
                  <TextView   
                      android:id="@+id/player_name"
                      android:layout_below="@id/player_image"
                      android:layout_centerHorizontal="true"
                      android:text="Raja Ram"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"/>
                  <ImageButton android:id="@+id/dialog_close"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentTop="true"
                      android:layout_alignParentRight="true"
                      android:background="#00000000"
                      android:src="@drawable/close_button_selector"/>
                  <ImageButton android:id="@+id/dialog_flip"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentTop="true"
                      android:layout_alignParentLeft="true"
                      android:background="#00000000"
                      android:src="@drawable/rotate"/>
                  </RelativeLayout>
                  

                  如您所见,我在此代码示例中使用 wrap_content 的所有地方.我也尝试了以下选项

                  As you can see, everywhere I am using wrap_content in this code sample. Also I tried the following options

                  1) 像这样创建对话框时设置自定义样式.

                  1) Setting a custom style while creating the Dialog like this.

                  dialog = new Dialog(this,R.style.Theme_Dialog);
                  

                  并且样式如下

                  <resources>
                  <style name="Theme" parent="android:Theme">
                  </style>
                  <style name="Theme.Dialog">
                      <item name="android:layout_width">wrap_content</item>
                      <item name="android:layout_height">wrap_content</item>
                      <item name="android:windowIsFloating">true</item>
                      <item name="android:windowContentOverlay">@null</item>
                      <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
                      <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
                  </style>
                  </resources>
                  

                  2) 像这样在 onCreateDialog() 中设置视图的参数

                  2) Setting the parameters for the view in the onCreateDialog() like this

                  LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  v = inflater.inflate(R.layout.player_info, null, false);
                  ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
                  dialog.setContentView(v,p);
                  

                  3) 我也尝试在 onCreateDialog() 方法中设置这样的 Window 参数

                  3) I also tried to set the Window parameters like this in the onCreateDialog() method

                  WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                  params.width=WindowManager.LayoutParams.WRAP_CONTENT;
                  dialog.getWindow().setAttributes(params);
                  

                  但还是没有运气.有人可以帮我解决这个问题.难道我做错了什么??您能否建议我如何设置对话框窗口的 x 和 y 位置?

                  But again no luck. Can someone help me out with this issue. Am I doing something wrong?? Also can you please suggest me how to set the x and y postions for the Dialog window?

                  谢谢

                  推荐答案

                  找了好久才发现问题.问题在于我使用相对布局的方式.我想我没有正确指定相对位置.当我将其更改为线性布局时,它工作正常.它并没有用完整个屏幕,而是只用了需要的东西.

                  I figured out the problem after a long time. The problem was with the way I used Relative layout. I guess I have not specified the relative position properly. When I changed that to linear layout it worked fine. It was not using up the whole screen but only whatever is required.

                  这篇关于在 Android 中创建自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Android VideoView:对话框视图中的视频视图要暗得多 下一篇:禁止谷歌地图意图选择对话框

                  相关文章

                  最新文章

                • <small id='4VMTJ'></small><noframes id='4VMTJ'>

                  <tfoot id='4VMTJ'></tfoot>
                  <legend id='4VMTJ'><style id='4VMTJ'><dir id='4VMTJ'><q id='4VMTJ'></q></dir></style></legend>
                      <bdo id='4VMTJ'></bdo><ul id='4VMTJ'></ul>

                    <i id='4VMTJ'><tr id='4VMTJ'><dt id='4VMTJ'><q id='4VMTJ'><span id='4VMTJ'><b id='4VMTJ'><form id='4VMTJ'><ins id='4VMTJ'></ins><ul id='4VMTJ'></ul><sub id='4VMTJ'></sub></form><legend id='4VMTJ'></legend><bdo id='4VMTJ'><pre id='4VMTJ'><center id='4VMTJ'></center></pre></bdo></b><th id='4VMTJ'></th></span></q></dt></tr></i><div id='4VMTJ'><tfoot id='4VMTJ'></tfoot><dl id='4VMTJ'><fieldset id='4VMTJ'></fieldset></dl></div>