在RelativeLayout Android中移动ImageView

时间:2015-06-04 13:46:31

标签: android android-layout android-activity

我有一个带有android的imageView:scaleType =" matrix"

<ImageView
    android:id="@+id/imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="20dp"
    android:scaleType="matrix"
    android:src="@drawable/ic_launcher" />

我想将此ImageView向左拖动,以查看屏幕外的图像部分。

换句话说,我想将此图像移动到我在ImageView上标记点的位置。

请帮忙。谢谢

1 个答案:

答案 0 :(得分:0)

将您的Imageview放入Framelayout并使用以下代码移动它:

Java代码:

_frameLayout.setX(Position);

_frameLayout.setY(Position);

示例XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_material_dark" >

    <ImageView 
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@drawable/ic_launcher"/>

    <FrameLayout
        android:id="@+id/framelayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:background="#ffffff" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/img"
                android:layout_width="110dp"
                android:layout_height="200dp"
                android:layout_centerHorizontal="true"
                android:background="@drawable/ic_launcher" />
        </RelativeLayout>
    </FrameLayout>
相关问题