Goal:
When click on the button, I would like to change the picture's X and Y coordinate to
android:layout_x 35dp android:layout_y: 541dp by using java code and not XML code.
Questions:
I cannot find the correct syntax code in order do it.
Do you know how to do it?
Thank you!
Info:
*I'm newbie in android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jfdimarzio.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="158dp"
android:layout_y="77dp"
android:src="@drawable/cat" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="testtest"
android:text="Button" />
</AbsoluteLayout>
package com.jfdimarzio.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView myImageView = (ImageView) findViewById(R.id.imageView2);
myImageView .setImageResource(R.drawable.cat);
}
public void testtest(View view)
{
AbsoluteLayout relativeLayout = new AbsoluteLayout(this);
ImageView myImageView = (ImageView) findViewById(R.id.imageView2);
myImageView.layout(10,10,10,10);
//myImageView.layout(3,3,3,3);
}
}