1

我有一个奇怪的问题。

我有一个 ImageView,在这个 ImageView 上是一个 WebView。此 WebView 与 ImageView 一样大,并且其背景是透明的,因此 WebView 仅显示文本。

在我的 Galaxy Nexus 上,这非常有效。但是在我的 Sony Xperia 上,WebView 没有对齐图像的顶部和底部。左对齐是好的

但是为什么会这样呢?

这是我的xml代码:

 <ImageView
    android:id="@+id/ImageView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:src="@drawable/product_pic_background" />

<RelativeLayout
    android:id="@+id/contain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignBottom="@+id/ImageView02"
    android:layout_alignLeft="@+id/ImageView02"
    android:layout_alignRight="@+id/ImageView02"
    android:layout_alignTop="@+id/ImageView02"
    android:orientation="vertical"
    android:paddingBottom="15dp"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:paddingTop="50dp" >

    <WebView
        android:id="@+id/produkttext"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:layout_alignParentStart="true"           
        android:longClickable="false"
        android:scrollbars="vertical" />
</RelativeLayout>

Xperia弧。 它不应该是怎样的

银河连结。 应该如何

1.Xperia弧。它怎么不应该是 2.Galaxy Nexus。应该如何

4

1 回答 1

2

好的,一旦我们有要求,一个解决方案:

<RelativeLayout
    android:id="@+id/contain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="15dip"
    android:paddingLeft="15dip"
    android:paddingRight="15dip"
    android:paddingTop="50dip" >

    <WebView
        android:id="@+id/produkttext"
        android:longClickable="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:background="@+drawable/product_pic_background"
        android:scrollbars="vertical" />
</RelativeLayout>

然后在代码中:

WebView web = (WebView) findViewById(R.id.produkttext);
web.setBackgroundColor(0);
BitmapDrawable bd=(BitmapDrawable) this.getResources().getDrawable(R.drawable.product_pic_background);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.yourId);
rl.getLayoutParams().height = bd.getBitmap().getHeight();
rl.getLayoutParams().width = bd.getBitmap().getWidth();

这将使WebView透明,以便查看背景图像,以及通过宽度和高度匹配父布局。然后,RelativeLayout将设置图片可绘制对象的尺寸。我还没有设法测试它(我现在不能),但如果这不起作用,我将删除此评论(并且可能会提交 harakiri :-))。

于 2013-07-12T15:01:25.627 回答