2016-04-18 5 views
0

ソフトキーボードを制御するinputMethodServiceがあります。ここでは画面が大きい場合、十分なボタンは、各画面の幅の1/5になるように、このコードの目的があるAndroid button.setWidth()は何もしません

@Override 
public View onCreateInputView() { 
    LayoutInflater lInflate = getLayoutInflater(); 
    Resources res = getResources(); 


    LinearLayout inputView = (LinearLayout) lInflate.inflate(R.layout.copypasta, null); 

    Button tab_navySeal = (Button) inputView.findViewById(R.id.tab_navySeal); 
    Button tab_thatsome = (Button) inputView.findViewById(R.id.tab_thatsome); 
    Button tab_thethingis = (Button) inputView.findViewById(R.id.tab_thethinggis); 
    Button tab_identify = (Button) inputView.findViewById(R.id.tab_identify); 
    Button tab_othercopypasta = (Button) inputView.findViewById(R.id.tab_otherpasta); 


    int sW = res.getDisplayMetrics().widthPixels; 

    int bWidth = sW/5; 
    Log.i("DEBUG_TAG", Integer.toString(bWidth)); 
    if(bWidth > 100) { 
     tab_navySeal.setWidth(bWidth); 
     tab_identify.setWidth(bWidth); 
     tab_thatsome.setWidth(bWidth); 
     tab_thethingis.setWidth(bWidth); 
     tab_othercopypasta.setWidth(bWidth); 

    } 

    return inputView; 
} 

の関連する部分です。それ以外の場合、画面が小さい場合、ボタンは100dpになります(HorizontalScrollViewで囲まれているので問題ありません)。

しかし、ソフトキーボードを開いても実際に何も起こっていません。上部の

enter image description here

ボタン各画面の1/5の代わりに広い100dpされなければならない:ここ

は、問題の画像です。この問題を考えると、各ボタンの幅はXMLで100dpに設定されています(プログラムの幅を設定するとXMLをオーバーライドする必要があるため、重要ではないとは思いますが)。

+0

制御は、ifブロック内で起こっていますか? –

+0

@Shadab安里「コントロール」とはどういう意味ですか? – Roymunson

+0

ブロック内にloggingステートメントを追加し、印刷されているかどうかを確認します。 @シャドーヴァンズ –

答えて

1

あなたはこのような新しい幅とLayoutParamsを設定してみてくださいすることができます -

tab_navySeal.setLayoutParams (new LayoutParams(bWidth, LayoutParams.WRAP_CONTENT); 
関連する問題