[英]Move ImageView inside RelativeLayout Android
我有一個帶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" />
我想將此ImageView
向左拖動以查看屏幕外的圖像部分。
換句話說,我想將此圖像移動到在ImageView
上標記該點的位置。
請幫忙。 謝謝
將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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.