2017-01-30 73 views
0

enter image description here應用樣式微調器

我想用微調項工作。 我希望下拉菜單具有與按鈕相同的寬度和高度。

我該怎麼做?

最後我解決它使用一個ListView到這樣的alertdialog:

public void seleccionaTemporada(View view) { 
     AlertDialog.Builder selector = new AlertDialog.Builder(SeleccionaTemporadaActivity.this); 
     selector.setTitle("Temporadas"); 

     selector.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       dialog.dismiss(); 
      } 
     }); 

     selector.setAdapter(temporadas, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       Intent intent = new Intent(getApplicationContext(), DashBoardActivity.class); 
       intent.putExtra("temporada", temporadas.getItem(which)); 
       startActivity(intent); 
      } 
     }); 
     selector.show(); 
    } 

<Button 
     android:id="@+id/btn_selecciona_temporada" 
     android:layout_width="300dp" 
     android:layout_height="200dp" 
     android:layout_alignParentStart="true" 
     android:layout_centerVertical="true" 
     android:layout_marginStart="70dp" 
     android:drawableStart="@mipmap/ic_balon" 
     android:onClick="seleccionaTemporada" 
     android:text="@string/seleccionarTemporada" 
     android:textSize="25sp" /> 

對於我的需求是最好的解決辦法,我認爲。對不起,我以前的不好解釋。

+0

佈局什麼是您​​使用?添加你的XML到這個問題將會很有幫助。 – Phantomazi

回答

1

您可以使用彈出窗口。並創建您自己的Spinner Popup。 示例代碼下面

LayoutInflater inflater = (LayoutInflater)parentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.pop_up_window, null); 
     RelativeLayout layout1 = holder.relativeLayout_multiChoiceDropDown; 

     pw = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); 

     pw.setBackgroundDrawable(new BitmapDrawable()); 
     pw.setTouchable(true); 
     pw.setOutsideTouchable(true); 
     pw.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 

     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.setContentView(layout); 
    pw.showAsDropDown(layout1, -5, 0); 

    final ListView list = (ListView) layout.findViewById(R.id.dropDownList); 
    Adapter_DropDown adapter = new Adapter_DropDown(parentActivity, items); 
    list.setAdapter(adapter); 

pop_up_window.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/PopUpView" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/qatool_basic_info_dropdown" 
       android:orientation="vertical"> 

    <ListView 
     android:id="@+id/dropDownList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#000" 
     android:dividerHeight="0.5dp"> 
    </ListView> 

</LinearLayout>