문제

그것은 설정이 가능한 폭의 회 드롭다운 목록에서 코드?나는 회로 채워진 정수,그리고 그것을 잘 보이지 않으로 목록을 확대하여 전체 폭입니다.을 설정할 수 있습니 폭을 감싸는 콘텐츠를 어떻게 든?

Spinner hSpinner = (Spinner) timerView.findViewById(R.id.timer_hour_spinner);
ArrayList<Integer> hList = new ArrayList<Integer>(21);

for (int i = 0; i <= 20; i++) { hList.add(i); }

ArrayAdapter hAdapter = new ArrayAdapter(RemindMe.this, android.R.layout.simple_spinner_item, hList);
hAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

hSpinner.setAdapter(hAdapter);

감사합니다!

라이너스

도움이 되었습니까?

해결책

코드의 폭을 조정하여 코드의 폭을 변경할 수 있습니다. LayoutParams. 그것의 세부 사항은 컨테이너에 따라 다릅니다.LinearLayout vs. RelativeLayout 대 ...).

그러나 "코드에서"너비를 변경하려는 이유가 혼란 스럽습니다. 너비를 설정하지 않겠습니까? wrap_content 레이아웃 XML에서?

다른 팁

그냥 사용 :

setDropDownWidth(desiredWidth);

그것은 간단하 제어 회 드롭다운 모니다.이것을 보십시오:

//Step 1. create the drop down list
static List<String> special_Spinner_Display_List = new ArrayList<String>();  
// add your values to the list...(this is best done using a for loop)
special_Spinner_Display_List.add(item1);
special_Spinner_Display_List.add(item2);  //etc., etc.

//Step 2. build the spinner
ArrayAdapter arrayAdapter_special = new ArrayAdapter(this, 
      R.layout.your_special_spinner, special_Spinner_Display_List);
arrayAdapter_special.setDropDownViewResource(R.layout.special_spinner_dropdown);
specialSpinner.setAdapter(arrayAdapter_special);

//Step 3. create an XML layout file called special_spinner_dropdown where you can 
//style to your heart's content.  Here's an example:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/SpinnerDropdown"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#D5ECED"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="24sp" 
android:textStyle="bold"
android:textColor="@color/black" />

그것입니다.Lemme 이 어떻게 작동하는지 알고 있!

태그를 사용하여 스피너의 XML 파일에서 드롭 다운 너비 설정

Android : Dropdownwidth = "@imen/desired_width"

설명 :

mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_dropDownWidth,
        ViewGroup.LayoutParams.WRAP_CONTENT);

이 필드는 스피너 클래스에서 스피너 항목이 초기화 될 때 드롭 다운 너비에 사용됩니다.

API 레벨 16 이상을 프로그래밍적으로 변경하는 스피너 드롭 다운 너비를 위해

mSpinner.setDropDownWidth(size_in_pixel);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top