简体   繁体   English

在RelativeLayout Android内部移动ImageView

[英]Move ImageView inside RelativeLayout Android

I have An imageView with android:scaleType="matrix" 我有一个带android:scaleType =“ matrix”的imageView

<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" />

I want to drag this ImageView to left to look at the parts of image which were off screen. 我想将此ImageView向左拖动以查看屏幕外的图像部分。

In other words I want to move this image to the point where I mark the point on ImageView . 换句话说,我想将此图像移动到在ImageView上标记该点的位置。

Please help. 请帮忙。 Thanks 谢谢

Put your Imageview Inside Framelayout and use following code to move it : 将Imageview放在Framelayout内,并使用以下代码将其移动:

Java Code: Java代码:

_frameLayout.setX(Position);

_frameLayout.setY(Position);

Example XML : 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM