画像が128x128の解像度でテーブルビューに挿入されたとき(画面全体をカバーする)私はそれらを256x256にリサイズし、スクリーン全体をカバーします。 9枚のパッチ画像などを使って画面全体を覆い、必要に応じてどの画面解像度でも動作させることはできませんか?密度を使用する必要がありますか?テーブルビューに画像を挿入すると画面全体が覆われない
私はfitXYを私のビューに設定しようとしましたが、私の問題は解決しませんでした。必要に応じて
は私はわからないが、ここに私のコードです:
私は4つのGIF画像ボタンを作成し、GIFイメージボタンのリストにそれらを追加しました:
for (int i = 0; i < 4; ++i) {
GifImageButton myButton = new GifImageButton();
myButton.setBackgroundResource(drawables[i]); // add some drawable to the button background
myButton.setLayoutParams(new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 1.0f));
listButtons.add(myButton);
}
は、その後、私はtablelayoutを作成したが(プログラムで行= 2、列= 2)と私のレイアウトにこれを追加しました:
MyTableLayout tableLayout = new MyTableLayout(this);
tableLayout.createTableLayoutOfButtons(tableRows /*=2*/, tableCols /*=2*/, listButtons);
mylinearLayout.addView(tableLayout);
私MyTableLayoutクラスは次のとおりです。
public class MyTableLayout extends TableLayout {
public MyTableLayout(Context context) {
super(context);
}
// indexListButtons is the current index of the listButtons elements. so as long as there are buttons, we will add them to the table rows
int indexListButtons = 0;
public void createTableLayoutOfButtons(int numRows, int numCols, List<GifImageButton> listButtons) {
setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
for (int i = 0; i < numRows; ++i) {
TableRow tableRow = new TableRow(getContext());
tableRow.setGravity(Gravity.CENTER);
tableRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT));
for (int j = 0; j < numCols; ++j, ++indexListButtons) {
// indices 0, 1, 2, 3
if (indexListButtons < listButtons.size()) {
tableRow.addView(listButtons.get(indexListButtons));
}
// indices bigger than 3 don't exist so insert empty views in order to make each of the views in the same size
else {
// not enough buttons
TableRow.LayoutParams params = new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 1.0f);
Button btn = new Button(getContext());
btn.setLayoutParams(params);
btn.setVisibility(View.INVISIBLE);
tableRow.addView(btn);
}
}
addView(tableRow);
}
}
}
======
EDIT
======
のVeselinトドロフ、これはあなたの意味だったなら、私は理解してみましょう。おかげで..
public class MyTableLayout extends TableLayout {
public MyTableLayout(Context context) {
super(context);
}
// indexListButtons is the current index of the listButtons elements. so as long as there are buttons, we will add them to the table rows
int indexListButtons = 0;
public void createTableLayoutOfButtons(int numRows, int numCols, List<GifImageButton> listButtons) {
setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
for (int i = 0; i < numRows; ++i) {
TableRow tableRow = new TableRow(getContext());
LinearLayout newLinearLayout = new LinearLayout(getContext());
newLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f));
newLinearLayout.setOrientation(LinearLayout.VERTICAL);
tableRow.addView(newLinearLayout, new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT, 1.0f));
tableRow.setGravity(Gravity.CENTER);
for (int j = 0; j < numCols; ++j, ++indexListButtons) {
// indices 0, 1, 2, 3
if (indexListButtons < listButtons.size()) {
newLinearLayout.addView(listButtons.get(indexListButtons));
}
// indices bigger than 3 don't exist so insert empty views in order to make each of the views in the same size
else {
// not enough buttons
TableRow.LayoutParams params = new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 1.0f);
Button btn = new Button(getContext());
btn.setLayoutParams(params);
btn.setVisibility(View.INVISIBLE);
newLinearLayout.addView(btn);
}
}
addView(tableRow);
}
}
}
テーブルの行の高さに重さを設定することで、これはボタンの幅と同じように行うことができます。このようにしてテーブルの行を分割すると、残りの空き領域が分割され、すべての垂直領域を満たす高さの行が得られます。 –
tableRow.setLayoutParams(新しいTableLayout.LayoutParams( TableLayout.LayoutParams.MATCH_PARENT、 0,1.0f)); このような意味ですか? \ –
そうですね、そうですね、TableLayoutのドキュメントによれば、子がTableRowの場合、高さは常にWRAP_CONTENTなので、体重が助けにならないと言います。これを修正するには2つの方法があります。 - ビューサイズを自分で計算することもできます。ポスト実行可能ファイルでこれを行うので、親レイアウトが既に高さを測定している次のフレームにサイズが設定されます。次に、ボタンの高さを親の高さの半分に設定するだけで、テーブルの行のサイズが正しく変更されます。 - もう1つの方法は、縦のLinearLayoutを、2つの子LinearLayoutsとその重みを設定して使用することです。 –