4

我有一个固定的背景图像,并在其上显示另一个图像。这是xml-

<AbsoluteLayout 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:orientation="vertical" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  >
 <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/lpch_1"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
        />
<ImageView 
     android:id="@+id/search_pin"
     android:src="@drawable/pin"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_y="100px" 
     android:layout_x="100px"
        />  
 </AbsoluteLayout>

现在,如何从代码中更改 image-id search_pin 的 layout_x、layout_y ?

4

3 回答 3

6

试试这个:

AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) test_image.getLayoutParams());
params.x = 100;
params.y = 100;
test_image.setLayoutParams(params); 
于 2011-10-14T10:43:44.763 回答
3

绝对布局已弃用。

对于这种情况,我建议使用FrameLayout

还有一件事,dpdippx更可取。

由于 android 支持多种屏幕分辨率,因此为特定小部件提及固定坐标并不好。

于 2011-10-14T10:37:29.400 回答
0

您必须使用Absolutelayout以下内容relativelayout

android:layout_x="100dp" 不是像素

android:layout_y="100dp"

都用于absolutelayout.

于 2015-09-30T08:37:33.323 回答