私はプログラムで動的にxml定義のテーブルレイアウトを入れる在庫管理Androidアプリをやっています。すべてのアイテムについて、私は2つのビュー:インベントリアイテムの名前を含むテキストビューと、3つのラジオボタンを含むラジオグループ:存在、欠落、および修復が必要なtablerowを作成します。また、テーブルレイアウトの各行の下には、テキストビューとエディットテキストが含まれていますが、その部分に問題がない線形レイアウトがあります。Tablerowの2行目に3ボタンラジオグループの1つのラジオボタンを移動させる
これは、それが現在どのように見えるかを示す私のスクリーンショットです:今 https://preview.ibb.co/k8a7Yw/Screenshot_20171011_170618.png
、ラジオボタンは、テキストようtablelayoutためのXMLにshrinkcolumn = 0を設定した後(自分の携帯電話の画面上で細かい表示します3番目のラジオボタンは途切れることはありません)、項目名は押しつぶされます。私がしたいのは、最後のラジオボタン(修理が必要)を一行下に移動することですが、ラジオグループと行に保持して、ラジオグループから継承するカスタムクラスを作成する必要はありません。
現在のコード:tablelayoutのXMLを
public class PMR {
String result;
String caption;
String repairString;
EditText repairEditText;
RadioButton pRadioButton;
RadioButton mRadioButton;
RadioButton rRadioButton;
public PMR(){
}
public PMR(final TableLayout tableLayout, final TableRow tableRow,
final Context context, String caption){
this.caption=caption;
result="incomplete";
repairString=null;
final RadioGroup radioGroup=new RadioGroup(context);
radioGroup.setTag("incomplete");
radioGroup.setOrientation(RadioGroup.HORIZONTAL);
tableRow.addView(radioGroup);
pRadioButton = new RadioButton(context);
pRadioButton.setText("Present");
pRadioButton.setId(generateViewId());
final int pId=pRadioButton.getId();
mRadioButton = new RadioButton(context);
mRadioButton.setText("Missing");
mRadioButton.setId(generateViewId());
final int mId=mRadioButton.getId();
rRadioButton = new RadioButton(context);
rRadioButton.setText("Repairs Needed");
rRadioButton.setId(generateViewId());
final int rId=rRadioButton.getId();
radioGroup.addView(pRadioButton);
radioGroup.addView(mRadioButton);
radioGroup.addView(rRadioButton);
final LinearLayout textLayout=new LinearLayout(context);
textLayout.setOrientation(LinearLayout.HORIZONTAL);
tableLayout.addView(textLayout);
textLayout.setTag("Text Row");
final TextView labelText = new TextView(context);
labelText.setText("");
textLayout.addView(labelText);
repairEditText = new EditText(context);
repairEditText.setEnabled(false);
repairEditText.setText("");
textLayout.addView(repairEditText);
final String prefix="Notes: ";
radioGroup.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged (RadioGroup group,
int checkedId){
if (checkedId!=rId &&
repairEditText.getText().toString()!=null){
repairString=repairEditText.getText().toString();
}
if (checkedId == pId) {
result="Present";
repairEditText.setText("");
repairEditText.setEnabled(false);
labelText.setText("");
radioGroup.setTag("pTag");
} else if (checkedId == mId) {
result="Missing";
repairEditText.setText("");
repairEditText.setEnabled(false);
labelText.setText("");
radioGroup.setTag("mTag");
} else if (checkedId == rId) {
result="Repairs Needed";
if (repairString!=null){
repairEditText.setText(repairString);
}
repairEditText.setEnabled(true);
repairEditText.requestFocus();
labelText.setText(prefix);
radioGroup.setTag("rTag");
}
else {
result = "incomplete";
radioGroup.setTag("incomplete");
}
}
});
}
}
は: https://image.ibb.co/i5qrtw/goodtablerowpmr.png
https://stackoverflow.com/questions/11891105/have-horizontal-radiobuttons-wrap-if-too-long -for-screen – HomeIsWhereThePcIs
そのポストの2つの回答のどちらも、提起された問題に答えなかった。最初はラジオグループでは機能せず、2番目のボタンでは部屋の外にある場合にのみ追加のボタンを下に移動します。私は自分の行を一様にしたいと思うし、すべて1ボタンの上に2つのボタンがあります。 – devander
最初の応答は、RadioGroupを拡張する、参照されているMultiLineRadioGroupクラスを使用します。 – HomeIsWhereThePcIs