我试图设置我的ImageView
调整大小,但它不能通过位图或其他方法工作我将放置我的代码所以如果有人可以帮助我如何调整大小ImageView
以适应表格行thnx。
public class Test extends Activity
{
private TableLayout Table1;
protected void onCreate(Bundle savedInstanceState)
{
int[] ImageArray={R.raw.hospital_image,R.raw.hotel_image};
super.onCreate(savedInstanceState);
setContentView(R.layout.favorites);
Table1 = (TableLayout) findViewById(R.id.Table);
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT, 1.0f);
for(int i=0;i<ImageArray.length;i++)
{
TableRow TR = new TableRow(this);
TR.setLayoutParams(tableRowParams);
ImageView img=new ImageView(this);
//What should i do here to resize it ???
Drawable d = getResources().getDrawable(ImageArray[i]);
img.setImageDrawable(d);
TR.addView(img, new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT, 1.0f));
Table1.addView(TR);
}
}
我的 XML 只包含这些:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TableLayout
android:id="@+id/Table1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
</RelativeLayout>