2011-12-29 2 views
3

두 개의 회전 장치를 서로 옆에 놓을 때이 문제가 있습니다. 다음은 레이아웃 XML의 단편은 : 여기 서로 옆에 두 개의 회전 장치가 있습니다.

... 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2" > 

    <Spinner 
     android:id="@+id/x" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|left" 
     android:layout_weight="1" /> 

    <Spinner 
     android:id="@+id/y" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|right" 
     android:layout_weight="1" /> 
</LinearLayout> 

<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <ListView 
     android:id="@+id/z" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:cacheColorHint="#FFFFFF" > 
    </ListView> 
... 
... 

는 결과이다 : 나는 많은 다른 것들을 시도

spinners

. 나는 가중치, 중력을 변경하려고 시도했으나 부모를 RelativeLayout으로 변경했지만 결과는 동일하게 유지되었습니다.

도와주세요!

편집 :

확인. 알았다. 약간의 중복성은 문제를 해결합니다. 왜 이상한가 작동하고 "정상적인 방법"하지 않습니다. 모두 도움을 주셔서 감사합니다.

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2" > 

    <Spinner 
     android:id="@+id/x" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 

    <RelativeLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 

     <Spinner 
      android:id="@+id/y" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" /> 
    </RelativeLayout> 
</LinearLayout> 
+0

문제가 재현되지 않습니다. 서로 옆에있는 두 개의 스피너 만 빼내려고 했습니까? 하나의 LinearLayout을 루트로, 두 개의 스피너를 하나씩 사용 했습니까? 또한 이클립스의 미리보기와 실제 장치/에뮬레이터에서이 문제가 발생합니까? –

답변

0

나는 그 정확한 문제를 본 적이 없지만, 둘 다 부모의 너비를 채우고있어 충돌 할 수 있습니다. 나는 그 크기를 결정하기 위해 가중치를 사용하는 모든 요소에 대해 android:layout_width="0dip"으로 대체 할 것입니다. 그러면 실제로는 같을 것입니다. RelativeLayout의에서

+0

방금 ​​변경했습니다. 불행히도 도움이되지 않았다. 이 문제가 풍경에도 나타나 있다고 덧붙이겠습니다. – Paul

+0

유감스럽게 생각합니다. 나는 질문을 upvoted, 잘하면 답변을 얻을 것이다. – Pyrodante

+0

감사합니다. 나는 그렇게 희망한다. – Paul

1

, 당신은 android:layout_toRightOf="@+id/x"android:layout_alignTop="@+id/x"을 사용할 수

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout> 
    <Spinner 
     android:id="@+id/x" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <Spinner 
     android:id="@+id/y" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/x" 
     android:layout_alignTop="@+id/x" /> 
</RelativeLayout> 

은 (그들이 당신의 회 전자의 텍스트에 영향을 보이지 않았다 나는 중력 정의를 남겨 두었다.)

+0

시도해보십시오. 주어진 솔루션을 정확히 사용하면 다음과 같은 결과를 얻을 수 있습니다. 첫 번째 (가장 왼쪽) 스피너가 부모를 채우고 다른 하나가 화면에서 벗어납니다. 또한 가로로 전환하면 예외가 발생합니다. 예외적으로 안드로이드는 "y"("y"는 두 번째 (가장 오른쪽)) 회 전자를 찾을 수 없다고 말합니다. – Paul

+0

첫 번째 스피너에 고정 폭을 설정하려고했습니다. 그게 효과가 있었어. 하지만 지금은 부모의 폭의 50 %를 정확하게 채울 필요가 없습니다.또한 위에서 언급 한 예외는 여전히 존재합니다. – Paul

-1

비록이 코드가 잘못된 것은 아니지만 wrap_content의 높이가 자동으로 linearlayout을 상단에두고 왼쪽 및 오른쪽이 모두 화면의 절반 너비이기 때문에 중력을 설정하지 않아도된다고 생각합니다.

그렇게 사용

<Spinner 
    android:id="@+id/x" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 

<Spinner 
    android:id="@+id/y" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 

+0

아니요. 같은 문제. 그래도 고마워. – Paul

5

이 나를 위해 잘 작동 :

<LinearLayout 
    android:id="@+id/x" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2"> 
    <Spinner 
     android:id="@+id/s1" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
    <Spinner 
     android:id="@+id/s2" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
</LinearLayout> 
0

대체 솔루션 어떤 일을 나를 위해. 다음과 같이 android : layout_gravity = "center_vertical"을 회 전자에 추가했습니다.

<LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:layout_marginTop="10dp" 
        android:orientation="horizontal" > 

        <Spinner 
         android:id="@+id/custSpinner" 
         style="@android:style/Widget.Spinner" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:layout_weight="1" 
         /> 

        <Spinner 
         android:id="@+id/busSpinner" 
         style="@android:style/Widget.Spinner" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:layout_weight="1" 
         /> 
       </LinearLayout> 
관련 문제