2011-09-30 11 views
0

アプリケーションの各行の先頭に1つの画像を配置したいとします。画像はtoo muchを縮小するという問題があります。私はそれがthe whole spaceを占有したいと思っています。テーブル行画像サイズの問題

main.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" 
     android:scrollbars="vertical" 
     > 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:id="@+id/tableView" 
     android:layout_height="fill_parent" 
     android:layout_weight=".90" 
     android:stretchColumns="1" 
      ></TableLayout> 
    </ScrollView> 

これは私がイメージを追加する方法です:

TableLayout tableView = (TableLayout) findViewById(R.id.tableView); 
     TableRow row = new TableRow(this); 
     ImageView im; 
     Bitmap bmp; 
     im = new ImageView(this); 
     bmp=getbmp(s); 
    im.setImageBitmap(bmp); 
     row.addView(im, new TableRow.LayoutParams(70, 30)); 
     tableView.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

私はTableRow.LayoutParams(70, 30));からパラメータを変更すると画像が同じまま、行のみが大きく/小さくなります。また、これらのパラメータを十分に小さくすると画像が小さくなる可能性がありますが、それは私がやりたいことではありません。私は必ずしも全体の画像を必要としませんが、その空間をいっぱいにする切り抜かれた画像がうまくいくでしょう。 Thisはウェブサイトの画像例です。私がこのような画像を置くと:row.addView(im);画像が大きくなりすぎ、テキストのためのスペースがなくなります。

+0

http://stackoverflow.com/questions/4811905/android-how-to-programmatically-set-width-of-imageview-inside-tablerow –

答えて

2

はそれが何であるか

TableLayout tableView = (TableLayout) findViewById(R.id.tableView); 

TableRow row = (TableRow) inflater.inflate(R.layout.tablerow, tableView, false); 

ImageView imgDis = (ImageView) row.findViewById(R.id.spinnerEntryContactPhoto); 

imgDis.setPadding(5, 5, 5, 5); 
imgDis.setAdjustViewBounds(true); 


// set row height width 
TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 50); 
params.topMargin = 0; 
params.bottomMargin = 0; 
params.leftMargin = 0; 
params.rightMargin = 0; 

// If you want to set margin of row 
tableView.addView(row, params); 
tablerow.xml 

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"> 

    <ImageView android:id="@+id/spinnerEntryContactPhoto" 
     android:layout_gravity="center_vertical" 
     android:layout_width="70dip" 
     android:layout_height="30dip"/> 
</TableRow> 
+0

あなたに役立つかもしれませんインフレータ? Eclipseでエラーが表示されます。 – Teo

+0

LayoutInflater inflater = getLayoutInflater();タブラウの上にそれを書いてください。 –

+0

imgDis.setAdjustViewBounds(true); 本当にありがとう! – bk138