android.widget.Spinner.setLayoutParams()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中android.widget.Spinner.setLayoutParams()方法的一些代码示例,展示了Spinner.setLayoutParams()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spinner.setLayoutParams()方法的具体详情如下:
包路径:android.widget.Spinner
类名称:Spinner
方法名:setLayoutParams

Spinner.setLayoutParams介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);
editTextAudioName.setLayoutParams(lp);
parentLayout.addView(editTextAudioName);

final Spinner spinnerListData = new Spinner(RecordAudio.this);
RelativeLayout.LayoutParams lpSpinner = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);
spinnerListData.setLayoutParams(lpSpinner);
 parentLayout.addView(spinnerListData);

代码示例来源:origin: stackoverflow.com

Spinner spinner = new Spinner(this);
//Make sure you have valid layout parameters.
  spinner .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

          ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
              android.R.layout.simple_spinner_dropdown_item, spinnerList);
          spinner.setAdapter(spinnerArrayAdapter);

代码示例来源:origin: stackoverflow.com

Spinner spinner = new Spinner(this);

spinner .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

        ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
            android.R.layout.simple_spinner_dropdown_item, spinnerList);
        spinner.setAdapter(spinnerArrayAdapter);

代码示例来源:origin: stackoverflow.com

Spinner spinner = new Spinner(this);
spinner .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
... 
...
//then you spinner adapter code 
linearlayout1.addView(spinner);

代码示例来源:origin: stackoverflow.com

final ActionBar actionBar = getActivity().getActionBar();
RelativeLayout relative = new RelativeLayout(getActivity());
Spinner spinner = new Spinner(getActivity());
spinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

relative.addView(spinner);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(relative);

// Set adapter and listener
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);

代码示例来源:origin: stackoverflow.com

private RelativeLayout root;
private Spinner spinner;

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.experimental);
  root = (RelativeLayout)findViewById(R.id.root_layout);
}

public void add(View v){
  spinner = new Spinner(this);
  ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(this,R.array.spinner,android.R.layout.simple_spinner_dropdown_item);
  spinner.setAdapter(spinnerAdapter);
  spinner.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  root.addView(spinner);
}![Added on Button Click][1]

代码示例来源:origin: stackoverflow.com

private void createDynamicSpinner() {

//Remove this line from top in your code and add here
Spinner spnOutHospitalList = new Spinner(Referance.this);

  spnOutHospitalList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

  //Pass Spinner Object to this function to load data in it!
  loadOutHospitalListSpinner(spnOutHospitalList);
  spnOutHospitalList.performClick();

spnOutHospitalList.setOnItemSelectedListener(new OnItemSelectedListener() {
  @Override
  public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long arg3) {
  // TODO Auto-generated method stub
  outHospitalName = hospitalNameListArray.get(position);
  outHospital.setText(outHospitalName);
  }
  @Override
  public void onNothingSelected(AdapterView<?> arg0) {
  // TODO Auto-generated method stub
  }
});
}

代码示例来源:origin: stackoverflow.com

LinearLayout leftSideAttributLayout = new LinearLayout(this);
     leftSideAttributLayout.setOrientation(LinearLayout.HORIZONTAL);
     LinearLayout.LayoutParams attributLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
     attributLayoutParams.gravity = Gravity.CENTER;
     leftSideAttributLayout.setLayoutParams(attributLayoutParams);
     leftSideAttributLayout.setGravity(Gravity.CENTER);
     LinearLayout.LayoutParams leftLabelParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
     //leftLabelParams.gravity = Gravity.CENTER;
     TextView leftAttributLabel = new TextView(this);
     leftAttributLabel.setText("sample");
     leftAttributLabel.setTextSize(25);
     leftAttributLabel.setLayoutParams(leftLabelParams);
     LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
     // spinnerParams.gravity = Gravity.CENTER;
     spinnerParams.setMargins(10, 0, 0, 0);
     Spinner leftAttributValues = new Spinner(this);
     leftAttributValues.setLayoutParams(spinnerParams);
     leftSideAttributLayout.addView(leftAttributLabel);
     leftSideAttributLayout.addView(leftAttributValues);
     mainview.addView(leftSideAttributLayout);

代码示例来源:origin: stackoverflow.com

public class WvActivity extends Activity {

TextView tx;
String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica",
    "India ", "Arica", "India ", "Arica" };
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this,
      android.R.layout.simple_spinner_item, s);

  tx= (TextView)findViewById(R.id.txt1);
  final Spinner sp = new Spinner(WvActivity.this);
  sp.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
  sp.setAdapter(adp);

  AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this);
  builder.setView(sp);
  builder.create().show();
 }
 }

代码示例来源:origin: stackoverflow.com

public class WvActivity extends Activity {

 TextView tx;
 String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica",
  "India ", "Arica", "India ", "Arica" };
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this,
    android.R.layout.simple_spinner_item, s);

 tx= (TextView)findViewById(R.id.txt1);
 final Spinner sp = new Spinner(WvActivity.this);
 sp.setLayoutParams(new     LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
 sp.setAdapter(adp);

 AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this);
 builder.setView(sp);
 builder.create().show();
 }
}

代码示例来源:origin: stackoverflow.com

ImageButton bracket = (ImageButton) findViewById(R.id.imageButton1);
 bracket.setOnClickListener(new OnClickListener() {
   public void onClick(View arg0) {
     ArrayAdapter<String> adp = new ArrayAdapter<String>(arg0.getContext(), android.R.layout.simple_spinner_item, s);
     Spinner sp = new Spinner(arg0.getContext());
     AlertDialog.Builder builder = new AlertDialog.Builder(arg0.getContext());
     sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
       public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
         choosed_bracket = (String) sp.getItemAtPosition(i);
       }
       public void onNothingSelected(AdapterView<?> adapterView) {
         return;
       }
     });
     sp.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
     sp.setAdapter(adp);
     builder.setTitle("Choose war bracket:");
     builder.setView(sp);
     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int which) {
         /*SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
         SharedPreferences.Editor editor = settings.edit();
         editor.putString("bracket", choosed_bracket);
         editor.commit(); */
         Toast.makeText(getApplicationContext(), "Choosed bracket is: " + choosed_bracket, Toast.LENGTH_LONG).show();
       }
     });

代码示例来源:origin: stackoverflow.com

public class WvActivity extends Activity {
 TextView tx;
 String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica",
     "India ", "Arica", "India ", "Arica" };
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this,
       android.R.layout.simple_spinner_item, s);
   tx= (TextView)findViewById(R.id.txt1);
   final Spinner sp = new Spinner(WvActivity.this);
   sp.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
   sp.setAdapter(adp);
   AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this);
   builder.setView(sp);
   builder.create().show();
  }
  }

代码示例来源:origin: stackoverflow.com

/**
 * Creates a new {@link Spinner} which overlays another
 * @param spinner {@link Spinner} to overlay
 * @return The new {@link Spinner}
 */
private Spinner createNewSpinner(Spinner spinner){
  LayoutParams spinnerParams = new LayoutParams(spinner.getWidth(), LayoutParams.WRAP_CONTENT);
  spinnerParams.addRule(RelativeLayout.ALIGN_TOP, spinner.getId());
  spinnerParams.addRule(RelativeLayout.ALIGN_LEFT, spinner.getId());

  Spinner overlaySpinner = new Spinner(HomeActivity.this);
  overlaySpinner.setLayoutParams(spinnerParams);

  return overlaySpinner;
}

代码示例来源:origin: stackoverflow.com

// try this way,hope this will help you...
   Spinner newMobileSpinner = new Spinner(this);
   newMobileSpinner.setLayoutParams(new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
   newMobileSpinner.setAdapter(arrayAdpType);
   EditText newMobileEditText = new EditText(this);
   newMobileEditText.setLayoutParams(new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
   newMobileEditText.setHint("Mobile No");
   newMobileEditText.setBackgroundResource(android.R.drawable.editbox_background_normal);
   newMobileEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
   Button newBtnRemove = new Button(this);
   newBtnRemove.setLayoutParams(new LinearLayout.LayoutParams(0,45, 1f));
   newBtnRemove.setBackgroundResource(R.drawable.minusred);
   LinearLayout Matrix = (LinearLayout)findViewById(R.id.sub5);
   LinearLayout layout = new LinearLayout(this);
   layout.setOrientation(LinearLayout.HORIZONTAL);
   layout.addView(newMobileSpinner);
   layout.addView(newMobileEditText);
   layout.addView(newBtnRemove);
   Matrix.addView(layout);

代码示例来源:origin: wasdennnoch/AndroidN-ify

@Override
protected void onBindView(View view) {
  super.onBindView(view);
  if (view.equals(mSpinner.getParent())) return;
  if (mSpinner.getParent() != null) {
    ((ViewGroup) mSpinner.getParent()).removeView(mSpinner);
  }
  ViewGroup vg = (ViewGroup) view;
  vg.addView(mSpinner, 0);
  ViewGroup.LayoutParams lp = mSpinner.getLayoutParams();
  lp.width = 0;
  mSpinner.setLayoutParams(lp);
}

代码示例来源:origin: stackoverflow.com

Spinner leftAttributValues = new Spinner(this);
leftAttributValues.setAdapter(adapter);
leftAttributValues.setBackgroundResource(R.drawable.lenti_attributspinner);
leftAttributValues.setTag(attribut);

// get actual spinner params
LayoutParams params = (LayoutParams) leftAttributValues.getLayoutParams();
// modify desired params 
params.gravity = Gravity.CENTER_HORIZONTAL;
params.setMargins(10, 0, 0, 0);
// set modified params to spinner again
leftAttributValues.setLayoutParams(params);

代码示例来源:origin: henrichg/PhoneProfilesPlus

mEndSpinner.setLayoutParams(
    new TableLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));

代码示例来源:origin: stackoverflow.com

else if(v == btnAddChild)
 {
   LinearLayout dynamicLayout = new LinearLayout(this);
   LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
   params.weight = 1.0f;
   params.gravity = Gravity.CENTER_VERTICAL;
   dynamicLayout.setLayoutParams(params);
   dynamicLayout.setOrientation(LinearLayout.HORIZONTAL);
   int layoutId = totalDynamicChild + 1000; //dynamicLayout always have dynamic spinnser's id + 1000 to avoid same id
   dynamicLayout.setId(layoutId);
   Spinner spinner = new Spinner(this);
   spinner.setLayoutParams(params);
   spinner.setAdapter(spinChildAdapter);
   spinner.setId(totalDynamicChild);   
   spinnderIdList.add(totalDynamicChild);
   ImageButton btn = new ImageButton(this);
   btn.setImageDrawable(getResources().getDrawable(R.drawable.action_delete));
   btn.setBackgroundResource(0);
   btn.setLayoutParams(params);
   int btnId = totalDynamicChild + 2000; //btn always have dynamic spinnser's id + 2000 to avoid same id
   btn.setId(btnId);
   dynamicLayout.addView(spinner);
   dynamicLayout.addView(btn);
   parentSpinner.addView(dynamicLayout);
   totalDynamicChild++;

代码示例来源:origin: stackoverflow.com

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setLayoutParams(lp);
this.addView(spinner);

代码示例来源:origin: yaozs/YzsLib

params.gravity = Gravity.TOP;
params.setMargins(tenPx, tenPx, tenPx, 0);
mSpringSelectorSpinner.setLayoutParams(params);
container.addView(mSpringSelectorSpinner);

相关文章