4

相対的なレイアウトでかなり奇妙な動作を観察します。

これは初期状態です: ここに画像の説明を入力してください

定義:

<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");

そしてこれに変わります:
ここに画像の説明を入力してください

2番目の画像でEditTextbleedCountの高さが非常に高いことに注目してください。の値がbleedCount.getHeight()72から95に変化していて、何が原因なのか理解できません。

4

3 に答える 3

2

EditTextが幅を変更したとき、ビューが表示された後、2行に分割されている必要があります。android:ems="10"
x12

ems特定のフォントに対して1文字のサイズがあります。

私はあなたが必要ないと思いますems
EditTextを1行に設定します。android:singleLine="true"

于 2012-07-11T19:50:35.450 に答える
1

bleedCountEditTextのサイズ変更は、ヒントテキストが1行より長くなるため(pos == 1)です。

コードの次の行をコメントアウトすると、サイズ変更は停止します。

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

サイズ変更を防ぐために、短く/小さくすることができますか?

于 2012-07-15T01:14:55.657 に答える
0

さて、私はあなたのコードベース全体を持っていないので、あなたがしていることを複製するために何か簡単なものをまとめました。参考までに、私はICS4.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
}
}

それが役に立てば幸い...

于 2012-07-14T23:41:53.303 に答える