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

    1. <small id='fKXpU'></small><noframes id='fKXpU'>

      • <bdo id='fKXpU'></bdo><ul id='fKXpU'></ul>
      1. <legend id='fKXpU'><style id='fKXpU'><dir id='fKXpU'><q id='fKXpU'></q></dir></style></legend>
        <tfoot id='fKXpU'></tfoot>

        如何更改弹出项目宽度大小?

        时间:2024-04-14

        <tfoot id='ZXgSD'></tfoot>

            <tbody id='ZXgSD'></tbody>
          • <small id='ZXgSD'></small><noframes id='ZXgSD'>

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

                  <legend id='ZXgSD'><style id='ZXgSD'><dir id='ZXgSD'><q id='ZXgSD'></q></dir></style></legend>

                1. 本文介绍了如何更改弹出项目宽度大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用带有自定义项目的弹出菜单.这样的问题

                  I use popup menu with custom items.Problems like this

                  红线代表默认宽度大小.

                  Red lines represents to default width size.

                  但我想要自定义更小宽度的项目(代表红线).

                  but i want custom smaller width size of items(represents red lines).

                  public void onClick(View v) {  
                      //Creating the instance of PopupMenu  
                      PopupMenu popup = new PopupMenu(MainLayout.this, mSikBtn);  
                      popup.getMenuInflater().inflate(R.menu.poupup_menu, popup.getMenu());
                      popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  
                          public boolean onMenuItemClick(MenuItem item) {  
                              
                              return true;  
                           }  
                      });  
                  
                      popup.show();//showing popup menu  
                      }  
                  });
                  

                  布局xml文件

                  <ImageView
                          android:id="@+id/popupBtn"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:background="@android:color/transparent" 
                          android:src="@drawable/selector_sik"
                          android:layout_weight="1"
                          android:layout_margin="10dip"
                          />
                  

                  popup_menu.xml 文件

                   <?xml version="1.0" encoding="utf-8"?>
                  <menu xmlns:android="http://schemas.android.com/apk/res/android" >
                      <item  
                          android:id="@+id/one"  
                          android:title="A)."/>  
                        ...
                          
                      <item  
                          android:id="@+id/three"  
                          android:title="E)."/>  
                  
                  </menu>
                  

                  类似问题:stackoverflow.com我需要自定义弹出菜单

                  Similar question: stackoverflow.com I need to custom popup menu

                  推荐答案

                  和你一样,我尝试了很多改变弹出菜单的宽度但没有成功.不知何故,我找到了您可能正在寻找的解决方案.首先,我没有使用弹出菜单,而是使用弹出窗口.

                  Just like you, I tried a lot to change the width of the popup menu but was unsuccessful. Somehow, I found a solution you might be looking for. First, instead of using popup menu, I used popup window.

                  Step1:制作行布局:

                  Step1: Making a row layout:

                  <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      xmlns:tools="http://schemas.android.com/tools"
                      android:layout_width="match_parent"
                      android:layout_height="?android:attr/listPreferredItemHeight"
                      android:background="@android:drawable/list_selector_background"
                      android:orientation="vertical" 
                      android:padding="3dp">
                  
                      <TextView
                          android:id="@+id/ItemA"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginLeft="18dp"
                          android:layout_marginRight="15dp"
                          android:layout_marginTop="3dp"
                          android:text="A)"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          tools:ignore="HardcodedText" />
                  
                      <TextView
                          android:id="@+id/ItemB"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginLeft="18dp"
                          android:layout_marginRight="15dp"
                          android:layout_marginTop="10dp"
                          android:text="B)"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          tools:ignore="HardcodedText" />
                      <TextView
                          android:id="@+id/ItemC"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginLeft="18dp"
                          android:layout_marginRight="15dp"
                          android:layout_marginTop="10dp"
                          android:text="C)"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          tools:ignore="HardcodedText" />
                      <TextView
                          android:id="@+id/ItemD"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginLeft="18dp"
                          android:layout_marginRight="15dp"
                          android:layout_marginTop="10dp"
                          android:text="D)"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          tools:ignore="HardcodedText" />
                  
                  </LinearLayout>
                  

                  第二步:制作一个初始化弹窗的方法:

                  Step 2: Made a method to initialize popup window:

                  private PopupWindow initiatePopupWindow() {
                  
                              try { 
                  
                                  mInflater = (LayoutInflater) getApplicationContext()
                                          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                                  View layout = mInflater.inflate(R.layout.row, null);
                  
                                          //If you want to add any listeners to your textviews, these are two //textviews.
                                  final TextView itema = (TextView) layout.findViewById(R.id.ItemA);
                  
                  
                                  final TextView itemb = (TextView) layout.findViewById(R.id.ItemB);
                  
                  
                  
                                  layout.measure(View.MeasureSpec.UNSPECIFIED,
                                          View.MeasureSpec.UNSPECIFIED);
                                  mDropdown = new PopupWindow(layout,FrameLayout.LayoutParams.WRAP_CONTENT,
                                          FrameLayout.LayoutParams.WRAP_CONTENT,true);
                                  Drawable background = getResources().getDrawable(android.R.drawable.editbox_dropdown_dark_frame);
                                  mDropdown.setBackgroundDrawable(background);
                                  mDropdown.showAsDropDown(pop, 5, 5);
                  
                              } catch (Exception e) {
                                  e.printStackTrace();
                              }
                              return mDropdown;
                  
                          }
                  

                  第 3 步:只需在 onCreate() 中调用它:

                  Step 3: Simply calling it in the onCreate():

                  public class MainActivity extends Activity {
                  
                      ImageButton red, blue;
                  
                      private PopupWindow mDropdown = null;
                      LayoutInflater mInflater;
                      Button pop;
                  
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          setContentView(R.layout.activity_main);
                  
                          pop = (Button)findViewById(R.id.button1);
                          pop.setOnClickListener(new OnClickListener() {
                  
                              @Override
                              public void onClick(View v) {
                  
                                  initiatePopupWindow();
                  
                              }
                          });
                      }
                    }
                  

                  希望这对您有所帮助..如果可以,请接受我的回答..:)

                  Hope this helps you..If it does, accept my answer..:)

                  截图如下:

                  http://imageshack.com/a/img585/7388/dxjo.png

                  这篇关于如何更改弹出项目宽度大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在android溢出按钮上更改弹出菜单的位置? 下一篇:android PopupWindow 可以显示另一个 PopupWindow 吗?

                  相关文章

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

                    1. <legend id='qk3E8'><style id='qk3E8'><dir id='qk3E8'><q id='qk3E8'></q></dir></style></legend>
                    2. <small id='qk3E8'></small><noframes id='qk3E8'>