【问题标题】:How to set full image in Absolute Layout in android如何在android的绝对布局中设置完整图像
【发布时间】:2010-07-28 09:07:44
【问题描述】:

我在 AbsoluteLayout 中设置了图像,但它不会在 G1 上全屏显示,但是当我在 Nexus 中运行相同的应用程序时,它可以正常工作。

我在我的活动类中设置了 setContentView(new Test(this))。测试是我的 AbsoluteLayout 类。

我的代码如下:

public class Test extends AbsoluteLayout {public Test(Context context) {
   super(context);
   final RelativeLayout rl = new RelativeLayout(context);
    final android.widget.RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    rl.setLayoutParams(params);
    this.addView(rl, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));

    ImageView mImageView = new ImageView(context);mImageView.setImageBitmap(((DataStorage)context.getApplicationContext()).getImage());
    this.addView(mImageView);   }}

谁能告诉我为什么我没有在 G1 手机屏幕上获得完整图像?

【问题讨论】:

  • 不要使用 AbsoluteLayout。曾经。另外,为什么要在 AbsoluteLayout 中创建一个空的 RelativeLayout?您可能应该改用 XML 定义布局。
  • 是的,你是对的,但在我的应用程序中,我想在我的活动上画线和矩形。在java中你只能扩展一个类。我想访问 AbsoluteLayout 的 onScrollChanged() 事件的方法。在绝对布局中,您可以在屏幕上绘画。

标签: android android-layout


【解决方案1】:

我发现了我没有设置的问题

this.addView(mImageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-06
    • 2018-07-31
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多