1
这是我的XML代码:XML来等效动态XML从集合类
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
<Button
android:id="@+id/button_weather9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Πίσω" />
<ImageView
android:id="@+id/weather_icon"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:scaleType="fitXY"
android:src="@drawable/weather1" />
</LinearLayout>
但在我的应用我想我的类中,与同样的事情上面动态设定一个新的XML。我不知道参数究竟是什么。到目前为止,我已经写了这个。你能帮我与它完成缺少什么:
final LinearLayout test2 = new LinearLayout(this);
test2.setOrientation(LinearLayout.VERTICAL);
test2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
final Button Back = new Button(this);
Back.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Back.setText("Back");
test2.addView(Back);
final LoaderImageView image = new LoaderImageView(this, ImageUrl);
image.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
我更感兴趣的是ScaleType因为image.ScaleType(FILL)
不起作用。
是的正是这个。构造相同布局的Java代码。这是因为我在从应用程序加载任何图像之前在应用程序中添加了加载程序,到目前为止,我只能通过动态设置xml来完成此工作。因为它只有一个xml我认为更容易使java代码给我与我想要的相同的布局,因为有一个静态的xml。 – ghostrider 2012-01-13 00:26:23