How to move Image to position x, y coordinate with current scale and padding












3














I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.



When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.



mPhotoView.setPadding(150, 150, 0, 0);


image with left padding



But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.



mPhotoView.setPadding(0, 0, 150, 150);     //Issue here.


Image with right padding










share|improve this question





























    3














    I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.



    When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.



    mPhotoView.setPadding(150, 150, 0, 0);


    image with left padding



    But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.



    mPhotoView.setPadding(0, 0, 150, 150);     //Issue here.


    Image with right padding










    share|improve this question



























      3












      3








      3


      5





      I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.



      When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.



      mPhotoView.setPadding(150, 150, 0, 0);


      image with left padding



      But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.



      mPhotoView.setPadding(0, 0, 150, 150);     //Issue here.


      Image with right padding










      share|improve this question















      I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.



      When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.



      mPhotoView.setPadding(150, 150, 0, 0);


      image with left padding



      But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.



      mPhotoView.setPadding(0, 0, 150, 150);     //Issue here.


      Image with right padding







      android android-layout android-imageview android-photoview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 at 7:00









      Nilesh Rathod

      29.7k82955




      29.7k82955










      asked Nov 22 at 13:19









      Abhay Koradiya

      6291322




      6291322
























          3 Answers
          3






          active

          oldest

          votes


















          1





          +50









          You need to use requestLayout() after setting padding in your mPhotoView




          public void requestLayout ()






          • Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.


          SAMPLE CODE



          <?xml version="1.0" encoding="utf-8"?>
          <RelativeLayout 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="match_parent"
          android:layout_height="match_parent"
          android:background="@color/colorAccent">

          <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerInParent="true"
          android:onClick="ClickMe3"
          android:text="Remove Padding " />

          <com.github.chrisbanes.photoview.PhotoView
          android:id="@+id/photo_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" />


          <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentStart="true"
          android:layout_alignParentBottom="true"
          android:onClick="ClickMe"
          android:text="left and top " />

          <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentEnd="true"
          android:layout_alignParentBottom="true"
          android:onClick="ClickMe2"
          android:text="right and bottom " />


          </RelativeLayout>



          Activity Code




          import android.support.v7.app.AppCompatActivity;
          import android.os.Bundle;
          import android.view.View;


          import com.github.chrisbanes.photoview.PhotoView;

          public class MainActivity extends AppCompatActivity {

          PhotoView mPhotoView;
          boolean flag = true;

          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

          mPhotoView = (PhotoView) findViewById(R.id.photo_view);
          mPhotoView.setImageResource(R.drawable.dishu);

          }

          public void ClickMe(View view) {

          mPhotoView.setPadding(150, 150, 0, 0);
          mPhotoView.requestLayout();

          }

          public void ClickMe2(View view) {

          mPhotoView.setPadding(0, 0, 150, 150);
          mPhotoView.requestLayout();
          }

          public void ClickMe3(View view) {

          mPhotoView.setPadding(0, 0, 0, 0);
          mPhotoView.requestLayout();

          }


          }


          Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY



          UPDATE



          as per your below comment




          My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.




          Actually Your padding Right and Bottom is working
          after setting padding you need to scroll your mPhotoView



          Like below code



          public class MainActivity extends AppCompatActivity {

          PhotoView mPhotoView;
          RelativeLayout rootView;

          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

          rootView = findViewById(R.id.rootView);
          mPhotoView = (PhotoView) findViewById(R.id.photo_view);

          mPhotoView.setImageResource(R.drawable.dishu);
          }

          public void Left_Top(View view) {
          mPhotoView.setPadding(150, 150, 0, 0);
          mPhotoView.requestLayout();
          }

          public void Right_Bottom(View view) {
          mPhotoView.setPadding(0, 0, 150, 150);
          mPhotoView.requestLayout();
          // after setting padding scroll your mPhotoView to bottom
          mPhotoView.scrollTo(150,150);
          }

          public void ClickMe3(View view) {
          mPhotoView.setPadding(0, 0, 0, 0);
          mPhotoView.requestLayout();
          mPhotoView.scrollTo(0,0);
          }


          }





          share|improve this answer























          • My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
            – Abhay Koradiya
            Nov 28 at 7:03










          • @AbhayKoradiya it actually setting padding after applying padding try to scroll image
            – Nilesh Rathod
            Nov 28 at 7:14










          • Yes It scrolls Perfectly, even I don't write requestlayout.
            – Abhay Koradiya
            Nov 28 at 7:14










          • But, I want effect like left padding (Auto scrolling).
            – Abhay Koradiya
            Nov 28 at 7:15










          • @AbhayKoradiya wait i will update my answer
            – Nilesh Rathod
            Nov 28 at 7:17



















          0














          You can use Parent Layout (LinearLayout or FramLayout)to apply your padding on and put your ImageView in it so its work according your requirements.



          OR



          You can use ScaleType property so it can be manage in a smooth way.






          share|improve this answer





















          • I want to zoom Imageview with out of boundry. so it can't help me.
            – Abhay Koradiya
            Nov 28 at 7:05



















          0














          You need to use constraints, put it in a ConstraintLayout and then set the edges to 0, or set the Constraint to how much you want it to not shift.



          https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431919%2fhow-to-move-image-to-position-x-y-coordinate-with-current-scale-and-padding%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1





            +50









            You need to use requestLayout() after setting padding in your mPhotoView




            public void requestLayout ()






            • Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.


            SAMPLE CODE



            <?xml version="1.0" encoding="utf-8"?>
            <RelativeLayout 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="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:onClick="ClickMe3"
            android:text="Remove Padding " />

            <com.github.chrisbanes.photoview.PhotoView
            android:id="@+id/photo_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe"
            android:text="left and top " />

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe2"
            android:text="right and bottom " />


            </RelativeLayout>



            Activity Code




            import android.support.v7.app.AppCompatActivity;
            import android.os.Bundle;
            import android.view.View;


            import com.github.chrisbanes.photoview.PhotoView;

            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            boolean flag = true;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            mPhotoView = (PhotoView) findViewById(R.id.photo_view);
            mPhotoView.setImageResource(R.drawable.dishu);

            }

            public void ClickMe(View view) {

            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();

            }

            public void ClickMe2(View view) {

            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            }

            public void ClickMe3(View view) {

            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();

            }


            }


            Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY



            UPDATE



            as per your below comment




            My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.




            Actually Your padding Right and Bottom is working
            after setting padding you need to scroll your mPhotoView



            Like below code



            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            RelativeLayout rootView;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            rootView = findViewById(R.id.rootView);
            mPhotoView = (PhotoView) findViewById(R.id.photo_view);

            mPhotoView.setImageResource(R.drawable.dishu);
            }

            public void Left_Top(View view) {
            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();
            }

            public void Right_Bottom(View view) {
            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            // after setting padding scroll your mPhotoView to bottom
            mPhotoView.scrollTo(150,150);
            }

            public void ClickMe3(View view) {
            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();
            mPhotoView.scrollTo(0,0);
            }


            }





            share|improve this answer























            • My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
              – Abhay Koradiya
              Nov 28 at 7:03










            • @AbhayKoradiya it actually setting padding after applying padding try to scroll image
              – Nilesh Rathod
              Nov 28 at 7:14










            • Yes It scrolls Perfectly, even I don't write requestlayout.
              – Abhay Koradiya
              Nov 28 at 7:14










            • But, I want effect like left padding (Auto scrolling).
              – Abhay Koradiya
              Nov 28 at 7:15










            • @AbhayKoradiya wait i will update my answer
              – Nilesh Rathod
              Nov 28 at 7:17
















            1





            +50









            You need to use requestLayout() after setting padding in your mPhotoView




            public void requestLayout ()






            • Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.


            SAMPLE CODE



            <?xml version="1.0" encoding="utf-8"?>
            <RelativeLayout 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="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:onClick="ClickMe3"
            android:text="Remove Padding " />

            <com.github.chrisbanes.photoview.PhotoView
            android:id="@+id/photo_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe"
            android:text="left and top " />

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe2"
            android:text="right and bottom " />


            </RelativeLayout>



            Activity Code




            import android.support.v7.app.AppCompatActivity;
            import android.os.Bundle;
            import android.view.View;


            import com.github.chrisbanes.photoview.PhotoView;

            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            boolean flag = true;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            mPhotoView = (PhotoView) findViewById(R.id.photo_view);
            mPhotoView.setImageResource(R.drawable.dishu);

            }

            public void ClickMe(View view) {

            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();

            }

            public void ClickMe2(View view) {

            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            }

            public void ClickMe3(View view) {

            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();

            }


            }


            Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY



            UPDATE



            as per your below comment




            My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.




            Actually Your padding Right and Bottom is working
            after setting padding you need to scroll your mPhotoView



            Like below code



            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            RelativeLayout rootView;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            rootView = findViewById(R.id.rootView);
            mPhotoView = (PhotoView) findViewById(R.id.photo_view);

            mPhotoView.setImageResource(R.drawable.dishu);
            }

            public void Left_Top(View view) {
            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();
            }

            public void Right_Bottom(View view) {
            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            // after setting padding scroll your mPhotoView to bottom
            mPhotoView.scrollTo(150,150);
            }

            public void ClickMe3(View view) {
            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();
            mPhotoView.scrollTo(0,0);
            }


            }





            share|improve this answer























            • My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
              – Abhay Koradiya
              Nov 28 at 7:03










            • @AbhayKoradiya it actually setting padding after applying padding try to scroll image
              – Nilesh Rathod
              Nov 28 at 7:14










            • Yes It scrolls Perfectly, even I don't write requestlayout.
              – Abhay Koradiya
              Nov 28 at 7:14










            • But, I want effect like left padding (Auto scrolling).
              – Abhay Koradiya
              Nov 28 at 7:15










            • @AbhayKoradiya wait i will update my answer
              – Nilesh Rathod
              Nov 28 at 7:17














            1





            +50







            1





            +50



            1




            +50




            You need to use requestLayout() after setting padding in your mPhotoView




            public void requestLayout ()






            • Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.


            SAMPLE CODE



            <?xml version="1.0" encoding="utf-8"?>
            <RelativeLayout 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="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:onClick="ClickMe3"
            android:text="Remove Padding " />

            <com.github.chrisbanes.photoview.PhotoView
            android:id="@+id/photo_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe"
            android:text="left and top " />

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe2"
            android:text="right and bottom " />


            </RelativeLayout>



            Activity Code




            import android.support.v7.app.AppCompatActivity;
            import android.os.Bundle;
            import android.view.View;


            import com.github.chrisbanes.photoview.PhotoView;

            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            boolean flag = true;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            mPhotoView = (PhotoView) findViewById(R.id.photo_view);
            mPhotoView.setImageResource(R.drawable.dishu);

            }

            public void ClickMe(View view) {

            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();

            }

            public void ClickMe2(View view) {

            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            }

            public void ClickMe3(View view) {

            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();

            }


            }


            Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY



            UPDATE



            as per your below comment




            My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.




            Actually Your padding Right and Bottom is working
            after setting padding you need to scroll your mPhotoView



            Like below code



            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            RelativeLayout rootView;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            rootView = findViewById(R.id.rootView);
            mPhotoView = (PhotoView) findViewById(R.id.photo_view);

            mPhotoView.setImageResource(R.drawable.dishu);
            }

            public void Left_Top(View view) {
            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();
            }

            public void Right_Bottom(View view) {
            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            // after setting padding scroll your mPhotoView to bottom
            mPhotoView.scrollTo(150,150);
            }

            public void ClickMe3(View view) {
            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();
            mPhotoView.scrollTo(0,0);
            }


            }





            share|improve this answer














            You need to use requestLayout() after setting padding in your mPhotoView




            public void requestLayout ()






            • Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.


            SAMPLE CODE



            <?xml version="1.0" encoding="utf-8"?>
            <RelativeLayout 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="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:onClick="ClickMe3"
            android:text="Remove Padding " />

            <com.github.chrisbanes.photoview.PhotoView
            android:id="@+id/photo_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe"
            android:text="left and top " />

            <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:onClick="ClickMe2"
            android:text="right and bottom " />


            </RelativeLayout>



            Activity Code




            import android.support.v7.app.AppCompatActivity;
            import android.os.Bundle;
            import android.view.View;


            import com.github.chrisbanes.photoview.PhotoView;

            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            boolean flag = true;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            mPhotoView = (PhotoView) findViewById(R.id.photo_view);
            mPhotoView.setImageResource(R.drawable.dishu);

            }

            public void ClickMe(View view) {

            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();

            }

            public void ClickMe2(View view) {

            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            }

            public void ClickMe3(View view) {

            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();

            }


            }


            Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY



            UPDATE



            as per your below comment




            My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.




            Actually Your padding Right and Bottom is working
            after setting padding you need to scroll your mPhotoView



            Like below code



            public class MainActivity extends AppCompatActivity {

            PhotoView mPhotoView;
            RelativeLayout rootView;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            rootView = findViewById(R.id.rootView);
            mPhotoView = (PhotoView) findViewById(R.id.photo_view);

            mPhotoView.setImageResource(R.drawable.dishu);
            }

            public void Left_Top(View view) {
            mPhotoView.setPadding(150, 150, 0, 0);
            mPhotoView.requestLayout();
            }

            public void Right_Bottom(View view) {
            mPhotoView.setPadding(0, 0, 150, 150);
            mPhotoView.requestLayout();
            // after setting padding scroll your mPhotoView to bottom
            mPhotoView.scrollTo(150,150);
            }

            public void ClickMe3(View view) {
            mPhotoView.setPadding(0, 0, 0, 0);
            mPhotoView.requestLayout();
            mPhotoView.scrollTo(0,0);
            }


            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 28 at 9:30

























            answered Nov 28 at 5:42









            Nilesh Rathod

            29.7k82955




            29.7k82955












            • My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
              – Abhay Koradiya
              Nov 28 at 7:03










            • @AbhayKoradiya it actually setting padding after applying padding try to scroll image
              – Nilesh Rathod
              Nov 28 at 7:14










            • Yes It scrolls Perfectly, even I don't write requestlayout.
              – Abhay Koradiya
              Nov 28 at 7:14










            • But, I want effect like left padding (Auto scrolling).
              – Abhay Koradiya
              Nov 28 at 7:15










            • @AbhayKoradiya wait i will update my answer
              – Nilesh Rathod
              Nov 28 at 7:17


















            • My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
              – Abhay Koradiya
              Nov 28 at 7:03










            • @AbhayKoradiya it actually setting padding after applying padding try to scroll image
              – Nilesh Rathod
              Nov 28 at 7:14










            • Yes It scrolls Perfectly, even I don't write requestlayout.
              – Abhay Koradiya
              Nov 28 at 7:14










            • But, I want effect like left padding (Auto scrolling).
              – Abhay Koradiya
              Nov 28 at 7:15










            • @AbhayKoradiya wait i will update my answer
              – Nilesh Rathod
              Nov 28 at 7:17
















            My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
            – Abhay Koradiya
            Nov 28 at 7:03




            My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
            – Abhay Koradiya
            Nov 28 at 7:03












            @AbhayKoradiya it actually setting padding after applying padding try to scroll image
            – Nilesh Rathod
            Nov 28 at 7:14




            @AbhayKoradiya it actually setting padding after applying padding try to scroll image
            – Nilesh Rathod
            Nov 28 at 7:14












            Yes It scrolls Perfectly, even I don't write requestlayout.
            – Abhay Koradiya
            Nov 28 at 7:14




            Yes It scrolls Perfectly, even I don't write requestlayout.
            – Abhay Koradiya
            Nov 28 at 7:14












            But, I want effect like left padding (Auto scrolling).
            – Abhay Koradiya
            Nov 28 at 7:15




            But, I want effect like left padding (Auto scrolling).
            – Abhay Koradiya
            Nov 28 at 7:15












            @AbhayKoradiya wait i will update my answer
            – Nilesh Rathod
            Nov 28 at 7:17




            @AbhayKoradiya wait i will update my answer
            – Nilesh Rathod
            Nov 28 at 7:17













            0














            You can use Parent Layout (LinearLayout or FramLayout)to apply your padding on and put your ImageView in it so its work according your requirements.



            OR



            You can use ScaleType property so it can be manage in a smooth way.






            share|improve this answer





















            • I want to zoom Imageview with out of boundry. so it can't help me.
              – Abhay Koradiya
              Nov 28 at 7:05
















            0














            You can use Parent Layout (LinearLayout or FramLayout)to apply your padding on and put your ImageView in it so its work according your requirements.



            OR



            You can use ScaleType property so it can be manage in a smooth way.






            share|improve this answer





















            • I want to zoom Imageview with out of boundry. so it can't help me.
              – Abhay Koradiya
              Nov 28 at 7:05














            0












            0








            0






            You can use Parent Layout (LinearLayout or FramLayout)to apply your padding on and put your ImageView in it so its work according your requirements.



            OR



            You can use ScaleType property so it can be manage in a smooth way.






            share|improve this answer












            You can use Parent Layout (LinearLayout or FramLayout)to apply your padding on and put your ImageView in it so its work according your requirements.



            OR



            You can use ScaleType property so it can be manage in a smooth way.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 28 at 5:09









            Chetan Joshi

            3,45111420




            3,45111420












            • I want to zoom Imageview with out of boundry. so it can't help me.
              – Abhay Koradiya
              Nov 28 at 7:05


















            • I want to zoom Imageview with out of boundry. so it can't help me.
              – Abhay Koradiya
              Nov 28 at 7:05
















            I want to zoom Imageview with out of boundry. so it can't help me.
            – Abhay Koradiya
            Nov 28 at 7:05




            I want to zoom Imageview with out of boundry. so it can't help me.
            – Abhay Koradiya
            Nov 28 at 7:05











            0














            You need to use constraints, put it in a ConstraintLayout and then set the edges to 0, or set the Constraint to how much you want it to not shift.



            https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976






            share|improve this answer




























              0














              You need to use constraints, put it in a ConstraintLayout and then set the edges to 0, or set the Constraint to how much you want it to not shift.



              https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976






              share|improve this answer


























                0












                0








                0






                You need to use constraints, put it in a ConstraintLayout and then set the edges to 0, or set the Constraint to how much you want it to not shift.



                https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976






                share|improve this answer














                You need to use constraints, put it in a ConstraintLayout and then set the edges to 0, or set the Constraint to how much you want it to not shift.



                https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 28 at 5:13









                Chetan Joshi

                3,45111420




                3,45111420










                answered Nov 28 at 4:57









                Kingsley Mitchell

                585318




                585318






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431919%2fhow-to-move-image-to-position-x-y-coordinate-with-current-scale-and-padding%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Sphinx de Gizeh

                    Dijon

                    Guerrita