gpt4 book ai didi

android - 在绝对布局中设置图像位置

转载 作者:行者123 更新时间:2023-11-30 04:48:29 25 4
gpt4 key购买 nike

我在绝对面板中设置了一个图像。我试图通过代码设置它的位置。但是我没有看到任何适用的方法/属性来设置它的位置。

这是我的布局。

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>

<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/marker" android:src="@drawable/marker" android:layout_y="106dp" android:layout_x="290dp"></ImageView>
</AbsoluteLayout>

这是我设置位置的代码

marker = (ImageView)findViewById(R.id.marker);
marker.//Can't find a method or property

最佳答案

  • 不要使用 AbsoluteLayout。它已被弃用。使用 FrameLayout
  • 使用 FrameLayout,您可以为您的 View 创建一个 FrameLayout.LayoutParams 对象,并指定左侧和顶部的边距。
  • 如果您想为您的 View 设置动画,您可以使用 TranslateAnimation

如果您需要添加多个元素,请将它们封装到一个布局中并将它们放在您的 FrameLayout 下。

关于android - 在绝对布局中设置图像位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4236386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com