以绝对布局设置图像位置 [英] Set images position in absolute layout

查看:94
本文介绍了以绝对布局设置图像位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an image setup inside an absolute panel.I am trying to set it's position via code.But I do not see any applicable method/property to set its position.

这是我的布局.

<?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,可以为视图创建FrameLayout.LayoutParams对象,并在左侧和顶部指定边距.
  • 如果要为视图设置动画,可以使用TranslateAnimation.
    • Don't use AbsoluteLayout. It's deprecated. Use FrameLayout.
    • With a FrameLayout, you can create a FrameLayout.LayoutParams object for your view, and specify the margin on the left and top.
    • If you want to animate your view, you can use a TranslateAnimation.
    • 如果需要添加多个元素,请将其封装到布局中,然后将其放在FrameLayout下方.

      If you need to add multiple elements, encapsulate them into a layout and put those underneath your FrameLayout.

      这篇关于以绝对布局设置图像位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆