【问题标题】:Set images position in absolute layout在绝对布局中设置图像位置
【发布时间】:2010-11-21 04:07:50
【问题描述】:

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

这是我的布局。

<?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

【问题讨论】:

    标签: android android-layout


    【解决方案1】:
    • 不要使用AbsoluteLayout。它已被弃用。使用FrameLayout。
    • 使用 FrameLayout,您可以为视图创建 FrameLayout.LayoutParams 对象,并指定左侧和顶部的边距。
    • 如果要为视图设置动画,可以使用TranslateAnimation。

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

    【讨论】:

    • 我在这个应用中有两张图片。如何让图片 1 移动到图片 2 上方的某个位置?
    • 主布局中也有一些按钮。
    • Framelayout 只支持一张图片?
    • 如果您需要添加多个元素,请将它们封装到一个布局中,然后将它们放在您的 FrameLayout 下方。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    相关资源
    最近更新 更多