2011-09-30 65 views
0

我想在我的應用程序的每一行的開頭放一個圖像。問題是它縮小了圖像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