我试图以编程方式放置图像。但是当我放置图像时,它们会被拉伸。我正在使用 Micromax Canvas 来查看我的应用程序。
这是我的代码
void populateData(){
populate=(LinearLayout)findViewById(R.id.populate);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.weight=1.0f;
for(int i=0;i<10;i++) {
LinearLayout hr_populate=new LinearLayout(this);
hr_populate.setOrientation(LinearLayout.HORIZONTAL);
ImageView img=new ImageView(this);
img.setBackgroundResource(R.drawable.spicejet);
img.setLayoutParams(params);
ImageView img1=new ImageView(this);
img1.setBackgroundResource(R.drawable.book);
img1.setLayoutParams(params);
ImageView img2=new ImageView(this);
img2.setBackgroundResource(R.drawable.arrow);
img2.setLayoutParams(params);
TextView text = new TextView(this);
text.setText("BOS");
text.setLayoutParams(params);
TextView text1 = new TextView(this);
text1.setText("SAN");
text1.setLayoutParams(params);
TextView text2 = new TextView(this);
text2.setText("6h15m");
text2.setLayoutParams(params);
TextView text3 = new TextView(this);
text3.setText("32,163");
text3.setLayoutParams(params);
LinearLayout book_div = new LinearLayout(this);
book_div.setOrientation(LinearLayout.VERTICAL);
book_div.setLayoutParams(params);
book_div.addView(text3);
book_div.addView(img1);
hr_populate.addView(img);
hr_populate.addView(text);
hr_populate.addView(text1);
hr_populate.addView(text2);
hr_populate.addView(book_div);
hr_populate.addView(img2);
populate.addView(hr_populate);
}
}
这是我的 XML 代码
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@+id/sortFlightLayouts">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/populate"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
请建议我必须做出哪些改变才能摆脱这个问题