Issue
I have a inputMethodService
that controls a soft keyboard. Here is the relevant part of the
@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;
}
The purpose of this code is so that if the screen is large enough the buttons will each be 1/5 of the screen's width. Otherwise if the screen is small, the buttons will just be 100dp (which is fine since they are wrapped in a HorizontalScrollView
).
However nothing is actually happening when I open the softkeyboard.
Here is an image of the problem:
The buttons at the top should each be 1/5 of the screen instead of being 100dp wide. Incase this matters, the width of each button is set to 100dp in XML (even though I don't think it matters, because programmatically setting the widths should override the XML).
Solution
You can try setting LayoutParams
with the new width like this -
tab_navySeal.setLayoutParams (new LayoutParams(bWidth, LayoutParams.WRAP_CONTENT);
Answered By - Shadab Ansari
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.