2014-05-22 2 views
21

아래 이미지와 같은 스피너가 있습니다. 나는 가능한 한 낮게 내 응용 프로그램 요구 사항을 유지하기 위해 노력하고 있습니다로 API8에서 작동 바람직 솔루션 -스피너 드롭 다운에서 여백 제거

enter image description here

어떻게 스피너와 드롭 다운 사이의 x를 왼쪽의 격차를 제거 할 수 있습니다.

나는 이것이 spinner 스타일의 layout_margin이라고 가정했지만, this question을 읽은 후에는 불가능하다고 생각했습니다.

내가 가진 주제는 다음과 같습니다.

<style name="AppTheme" parent="AppBaseTheme">   
     <item name="android:dropDownListViewStyle">@style/DropDownStyle</item> 
    <item name="android:dropDownSelector">@style/DropDownStyle</item>     
</style> 


<style name="DropDownTopStyle"> 

    <item name="android:clickable">true</item> 
    <item name="android:background">@drawable/dropdowntop</item> 

</style> 

<style name="DropDownStyle"> 

    <item name="android:layout_width">fill_parent</item> 
    <item name="android:layout_height">fill_parent</item> 
    <item name="android:layout_marginLeft">0dp</item> 
    <item name="android:layout_margin">0dp</item> 

    <item name="android:clickable">true</item> 
    <item name="android:background">@drawable/dropdownback</item> 
    <item name="android:popupBackground">@drawable/dropdownback</item> 
    <item name="android:cacheColorHint">#FFF000</item>  
    </style> 

감사합니다, 토마스

추가; 코드에서 팝업을 직접 만들 수있는 방법이 있음을 알 수 있습니다. 필요하다면 어떻게 든 어댑터 팝업보기로 이동할 수 있습니까? (즉, 표시되는 목록). 전체 어댑터 동작을 처음부터 다시 만들려고 시도하는 것은 끔찍한 방법으로 보일 수 있습니다. 그러나 정상적인 팝업 동작을 비활성화하고 볼 수 있다면 짜증나는 오프셋없이 직접 팝업을 만들 수 있습니다.

+0

당신도 해결책을 마련 했습니까? –

+0

@AnubianNoob 레이아웃을 [paste bin] (http://pastebin.com)에 게시하십시오. – Simas

+0

꽤 일반적인 질문입니다. 서비스에 연결된 떠 다니는 창에 드롭 다운이있는 맞춤 회 전자가 있습니다. 내 레이아웃이 정말로 중요합니까? –

답변

-1

메신저 확실하지만

 <item name="android:padding">0dp</item> 

을 DropDownStyle이를 추가하거나 ui hierarchy 스크린 샷

2

당신이 항목의 목록을 보여줍니다 자신에 AlertDialog를 만들기 위해 스피너보기를 확장 할 필요가 보인다 공유 할 수 없거나 최신 버전 (API 16+)에 당신은 자세한 내용

android:dropDownHorizontalOffset="-8dp"

수표를 사용할 수 있습니다 그녀의 E : How to change the position of opened spinner?

0

이 시도, 이것은 내가 그것을 할 t know it is possible, because all view item like Spinner, EditText, etc... are small images in the android SDK. You should check, is there any default padding in the 9patched SDK image, if yes, I think you can t을 돈

<style name="DropDownStyle"> 

    <item name="android:layout_width">0dp</item> 
-2

작동합니다. 또한 안드로이드 소스 코드에서 기본 Spinner 클래스를 확인하는 것을 잊지 마세요, 아마도 몇 가지 트릭이 있습니다.

1

당신이 뭘 원하는거야?

활동 :

public class MainActivity extends Activity 
{ 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Spinner spinnerListOptions = (Spinner) findViewById(R.id.spinner); 
     ArrayAdapter<CharSequence> adapterListOptions = ArrayAdapter.createFromResource(this, R.array.string_array, 
      R.layout.spinner_item_top); 
     adapterListOptions.setDropDownViewResource(R.layout.spinner_item_dropdown); 
     spinnerListOptions.setAdapter(adapterListOptions); 
    } 
} 

spinner_item_top.xml :

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="29dp" 
     android:textSize="12sp" 
     android:gravity="center"> 
</TextView> 
그렇다면

enter image description here

는, 여기에 코드 (API 레벨 9까지 작동)(210)

spinner_item_dropdown.xml :

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="29dp" 
     android:textSize="12sp" 
     android:gravity="center"> 
</TextView> 

activity_main.XML :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

    <Spinner 
      android:id="@+id/spinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true"/> 

</RelativeLayout> 

strings.xml의 :

<resources> 
<string-array name="string_array"> 
    <item>item 1</item> 
    <item>item 2</item> 
    <item>item 3</item> 
</string-array> 
</resources> 
관련 문제