2012-07-11 8 views
4

상대적 레이아웃에서 약간 이상한 동작을 관찰합니다.이유없이 편집 텍스트 변경

이 초기 상태이다 enter image description here

중도 :

<EditText 
    android:id="@+id/bleedCount" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_toLeftOf="@+id/abrMult" 
    android:layout_below="@+id/textView4" 
    android:layout_marginRight="10dp" 
    android:ems="10" 
    android:inputType="number" 
    > 
    <requestFocus /> 
</EditText> 

<TextView 
    android:id="@+id/abrMult" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@+id/abrSubmit" 
    android:layout_alignBaseline="@+id/abrSubmit" 
    android:layout_marginRight="10dp" 
    android:text="x12" /> 

<Button 
    android:id="@+id/abrSubmit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView4" 
    android:layout_alignParentRight="true" 
    android:text="Calculate" /> 

드롭 다운에서 onItemSelected에서 그것 같이 변경되고 :

abrSubmit.setText(pos == 1 ? "Calculate" : "Submit"); 
abrMult.setVisibility(pos == 1 ? View.VISIBLE : View.GONE); 
bleedCount.setHint(pos == 1 ? "# of Meow/month" : "# of Meow/year"); 

이 변신 :
enter image description here

두 번째 그림에서 EditText bleedCount의 길이가 길어집니다. bleedCount.getHeight()의 값이 72에서 95로 변경되고 있으며 그 원인을 이해할 수 없습니다. 글고 x12가 전경의 게재 한 결과, 폭의 변경시

+0

문제점을 재현하려고 시도했습니다. 게시 한 코드를 복사/붙여 넣기하고 Cupcake 에뮬레이터에서 실행하고 아무런 문제가 보이지 않으면 editText 상자가 같은 높이를 유지합니다. 어떤 Android 버전을 사용하고 있습니까? EditText 상자를 사용자 정의하기 위해 다른 작업을 수행하고 있습니까? 특정 테마를 사용하고 있습니까? – Matthieu

+0

왜 3 가지 요소 (텍스트, 텍스트보기, 버튼 편집)에 대해 가중치를 사용하지 않고 가중치가있는 가로 선형 레이아웃에 넣으십시오. –

답변

1

bleedCount 글고 크기 조정은 ... 희망은 도움 인해 힌트 텍스트 때 (pos == 1)을 한 줄보다 더 오래되기 .

// bleedCount.setHint(pos == 1 ? "# of Meow/month" : "# of Meow/year"); 

어쩌면 당신은 make it shorter/smaller 크기 조정을 방지 할 수 있습니다 : 당신이 당신의 코드에서 다음 줄을 주석 경우

, 크기 조정이 일어나고 중지?

+0

정확히 그게 고마워. –

2

가 그것은 android:ems="10"
으로 연결되어, 두 개의 라인으로 splited되어 있어야.

ems은 주어진 글꼴에 대해 한 글자의 크기를가집니다.

ems이 필요하지 않다고 생각합니다.
설정 글고 치기는 단일로 줄 지어 : android:singleLine="true"

+0

'ems'를 제거하고'singleLine'을 추가했습니다. 같은 행동을 계속합니다. –

0

좋아, 전체 코드베이스를 가지고 있지 않기 때문에 나는 당신이 무엇을하고 있는지 복제하기 위해 함께 간단한 무언가를 넣어. 다만 FYI, 나는 ICS 4.1을 사용하고있다. 나는 당신이 가진 어떤 문제도 없었습니다. 아마도 이것은 API 문제 일 것입니다. 아마도 당신은 내 코드베이스를보고 그 코드와 자신의 코드베이스 사이의 차이점을 볼 수 있습니다. 거기에 해결책이있을 수 있습니다.

XML :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/main_rl" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<TextView 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Top TextView" /> 

<Spinner 
    android:layout_below="@+id/textView4" 
    android:id="@+id/spinner1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:layout_below="@+id/spinner1" 
    android:id="@+id/textView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Above EditText" /> 

<EditText 
    android:id="@+id/bleedCount" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/textView5" 
    android:layout_marginRight="10dp" 
    android:layout_toLeftOf="@+id/abrMult" 
    android:ems="10" 
    android:inputType="number" > 
</EditText> 

<TextView 
    android:id="@+id/abrMult" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView5" 
    android:layout_alignBaseline="@+id/abrSubmit" 
    android:layout_marginRight="10dp" 
    android:layout_toLeftOf="@+id/abrSubmit" 
    android:text="x12" 
    android:visibility="gone" /> 

<Button 
    android:id="@+id/abrSubmit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/textView5" 
    android:text="Submit" /> 

</RelativeLayout> 

코드 :

public class ExampleActivity extends Activity implements OnItemSelectedListener { 

private Button submitButton; 
private TextView tv; 
private Spinner spinner; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_example); 

    submitButton = (Button) findViewById(R.id.abrSubmit); 
    tv = (TextView) findViewById(R.id.abrMult); 
    spinner = (Spinner) findViewById(R.id.spinner1); 

    // create the data array for the spinner 
    String[] strings = { "This", "That", "The Other" }; 

    // create the spinner adapter 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
      android.R.layout.simple_spinner_item, strings); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

    // set the adapter on the spinner 
    spinner.setAdapter(adapter); 

    // set the event listener for the spinner 
    spinner.setOnItemSelectedListener(this); 
} 

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, 
     long arg3) { 
    if (submitButton.getText().equals("Calculate")) { 
     submitButton.setText("Submit"); 
     tv.setVisibility(View.GONE); 
    } else { 
     submitButton.setText("Calculate"); 
     tv.setVisibility(View.VISIBLE); 
    } 

} 

public void onNothingSelected(AdapterView<?> arg0) { 
    // TODO Auto-generated method stub 
} 
}